Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created html template based on bootstrap css and am trying to create wordpress theme from it now.

Created my own menu function for it, which basically just sets default config for wp_nav_menu function:

functions.php

<?php

function pin_menu(){

    $defaults = array(
        'theme_location'  => 'primary',
        'menu'            => 'nav-menu',
        'container'       => false,
        'container_class' => '',
        'container_id'    => '',
        'menu_class'      => 'nav-collapse collapse pull-right',
        'menu_id'         => '',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'before'          => '',
        'after'           => '',
        'link_before'     => '',
        'link_after'      => '',
        'items_wrap'      => false,
        'depth'           => 1,
        'walker'          => ''
    );

    return wp_nav_menu( $defaults );
}
?>

All this prints out this html:

<div class="nav-collapse collapse pull-right">
<ul>
<li class="page_item page-item-5"><a href="http://localhost/page5/">page5</a></li>
<li class="page_item page-item-7"><a href="http://localhost/page7/">page5</a></li>
<li class="page_item page-item-15"><a href="http://localhost/page15/">page15</a></li>
<li class="page_item page-item-17"><a href="http://localhost/page17/">page17</a></li>
<li class="page_item page-item-19"><a href="http://localhost/page19/">page19</a></li>
</ul>
</div>

I cant understand why though.

If i read the codex: http://codex.wordpress.org/Function_Reference/wp_nav_menu

Then i have set container to false... yet the code prints out div with the classes i have put for menu_class.

It wraps links with ul, even though i have set items_wrap to false.

This is not what i want though. I actually like this printout but i really cant understand it. And i also would like this ul, that wraps menu items to have certain class..

But when i set items_wrap to <ul class="nav">%3$s</ul> then nothing changes...

What would be correct config if i want this:

<div class="nav-collapse collapse pull-right">
<ul class="nav">
<li class="page_item page-item-5"><a href="http://localhost/page5/">page5</a></li>
<li class="page_item page-item-7"><a href="http://localhost/page7/">page5</a></li>
<li class="page_item page-item-15"><a href="http://localhost/page15/">page15</a></li>
<li class="page_item page-item-17"><a href="http://localhost/page17/">page17</a></li>
<li class="page_item page-item-19"><a href="http://localhost/page19/">page19</a></li>
</ul>
</div>

Thanks Alan

Edit: Codex also says, that if you want to remove ul wrapping you need to do something like :

<?php wp_nav_menu( array( 'items_wrap' => '%3$s' ) ); ?>

Sorry, but setting items_wrap does not change anything as far as i can see.

Edit2: OK, it seems to be matter of adding too many stats i guess. If i do exactly this:

<?php wp_nav_menu( array( 'items_wrap' => '%3$s' ) ); ?>

Then it works, but other stuff is not how i want. So i guess, i have to set minimal amount of settings, which works.

Edit3: Apparently different settings conflict themselves somewhere... I got what i wanted when i changed my settings to this:

<?php

function pin_menu(){

    $settings = array(
        'container'       => 'div',
        'container_class' => 'nav-collapse collapse pull-right',
        'container_id'    => '',
        'menu_class'      => '',
        'menu_id'         => '',
        'echo'            => true,
        'fallback_cb'     => 'wp_page_menu',
        'before'          => '',
        'after'           => '',
        'link_before'     => '',
        'link_after'      => '',
        'items_wrap'      => '<ul class="nav">%3$s</ul>',
        'depth'           => 1,
        'walker'          => ''
    );

    return wp_nav_menu( $settings );
}
?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you set option 'theme_location' => 'primary' you need to be sure that you have registered this menu by the code in functions.php :

register_nav_menu( 'primary', 'Primary Menu' );

And then you need to be sure that you set Primary Menu in Theme Locations here: /wp-admin/nav-menus.php

Otherwise, wordpress will call fallback function which is wp_page_menu with default options.

And if you remove 'theme_location' option you will get menu which you set in "menu" оption (in your case, menu with name "nav-menu"). If this menu does not exists, wordpress will show first created menu. If you didn't create any custom menu - wordpress will call fallback.

share|improve this answer
    
Sounds legit :P. thanks –  Zayatzz Jun 29 '13 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.