Brady Dowling
Brady Dowling

Reputation: 5522

wp_nav_menu() doesn't assign ul class

Using wp_nav_menu() doesn't seem to allow me to properly assign a class to my ul element. Here's my code for the menu:

wp_nav_menu( array( 
    'container' => false,
    'menu_class' => 'nav navbar-nav navbar-left',
    'theme_location' => 'primary'
) );

The issue is that this keeps assigning my menu classes as container classes, even though I've tried setting container to false and to ''. This ends up being my navbar html:

<div class="nav navbar-nav navbar-left">
  <ul>
    <li class="page_item page-item-31"><a href="https://wordpress-c9-bradydowling.c9.io/?page_id=31">Contact Us</a></li>
    <li class="page_item page-item-5"><a href="https://wordpress-c9-bradydowling.c9.io/?page_id=5">My Little Page</a></li>
    <li class="page_item page-item-2"><a href="https://wordpress-c9-bradydowling.c9.io/?page_id=2">Sample Page</a></li>
  </ul>
</div>

Here's the gist of my full header.php file in case that's relevant. According to the wp_nav_menu docs, this seems exactly the way I should be calling it.

Is there a setting somewhere or a version of a certain plugin that could be messing things up? Does it matter that I'm updated to Wordpress 4.4.2?

Upvotes: 3

Views: 2161

Answers (3)

Epitaph
Epitaph

Reputation: 5

In my case that was absent class in items_wrap template

'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'

Upvotes: 0

Martijn van Hoof
Martijn van Hoof

Reputation: 760

I had the same problem, the answer that is checked to be the solution didnt work for me. I found out I had made a small mistake. The name of my menu didnt match with this function: register_nav_menus

Upvotes: 0

Cyborg
Cyborg

Reputation: 1447

If the menu (WP admin area) is not set, then the "nav navbar-nav navbar-left" is applied to "container". In other words, it overwrites the "container_class".

If the menu is set, then the "menu_class" is applied to "ul".

Upvotes: 5

Related Questions