wp_nav_menu() custom container and container_id

So today I started work on my first WordPress theme and so far it’s been a lot of fun. However, I have had difficulty in getting wp_nav_menu() to do what I want.

Here’s what I want:

<nav id="topnav" class="menu">
   <ul>
      <li class="current_page_item"><a href="#" title="Home">Home</a></li>
      <li class="page_item page-item-2"><a href="#" title="About">About</a></li>
   </ul>
</nav>

Looking in the documentation, I would expect the following call to do what I want:

<?php wp_nav_menu(array( 'container' => 'nav', 'container_id' => 'topnav' )); ?>

But instead I get this:

<div class="menu">
   <ul>
      <li class="current_page_item"><a href="#" title="Home">Home</a></li>
      <li class="page_item page-item-2"><a href="#" title="About">About</a></li>
   </ul>
</div>

To me it looks like my custom parameters are being ignored as the output from wp_nav_menu() is exactly the same. Is there something I need to turn on somewhere to enable this or is there something else going on?

EDIT

Curiously, if I change menu_class it alters the div’s class (I expected the div to be the container) but changing menu_id does nothing.

EDIT 2

Even going into nav-menu-template.php and changing the defaults for container, container_id, container_class, menu_id does nothing. Changing menu_class to yyy will change the div’s class from menu to yyy.

4 Answers
4

i had the save problem: it’s because if you don’t create the menu in the admin wordpress use a fallback method and creates the menu out of all active pages … and if this happens than the options from wp_nav_menu are not used …

so: just create the menu in the admin and u can change the wrapper-tag to “nav”

Leave a Comment