Title: Using wp_nav_menu function to set classes
Last modified: June 14, 2021

---

# Using wp_nav_menu function to set classes

 *  Resolved [jerreds](https://wordpress.org/support/users/jerreds/)
 * (@jerreds)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/)
 * I am trying to use the wp_nav_menu() function to set classes on a menu, and I
   thought I was following the documentation exactly, but I’m not getting what I
   expected. Here is the code:
 *     ```
       <?php 
       	  wp_nav_menu( array(
       			'theme_location' => 'primary',
       			'container' => 'nav',
       			'container_class' => "collapse navbar-collapse",
       			'menu_class' => "navbar-nav",
       			'menu_item' => 'nav-item',
       		) );
       ?>
       ```
   
 * I expected a `nav` with the classes in container_class that contained a `ul` 
   with the classes in menu_class.
 * But what I get is a `<nav class="navbar-nav">`, inside it is a ul with no classes.
   
   Nothing has the classes `collapse navbar-collapse`.
 * Is anyone able to explain why it is overwriting like this, or what I have wrong
   here?
    -  This topic was modified 4 years, 11 months ago by [jerreds](https://wordpress.org/support/users/jerreds/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/#post-14551903)
 * I would expect the same thing. Perhaps there is code with filters affecting the
   menu? There are several that could change things: [https://developer.wordpress.org/reference/functions/wp_nav_menu/](https://developer.wordpress.org/reference/functions/wp_nav_menu/)
 * _There is no parameter called `'menu\_item'`._
 *  Thread Starter [jerreds](https://wordpress.org/support/users/jerreds/)
 * (@jerreds)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/#post-14551910)
 * You know what, I think I removed whatever it was that had it not working, it’s
   doing what I put from before. So thanks, I guess! The only thing I did was change
   how the menu is registered… Not just browser cache or anything, because I definitely
   double-checked all of that prior to posting.
 * …And thanks, I removed the menu item thing, I was looking at the classes on accident.
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [4 years, 11 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/#post-14552251)
 * As a note for this… I’ve seen this happen too with some menus that I’ve done,
   and the answer was that I had not set a menu in the admin area to be dipslayed
   in that menu location. That had WordPress whot eh fallback “default” menu structure,
   and that doesn’t take the same classes, etc, as it does when you set the menu
   correctly.
 *  [Mike Ritter](https://wordpress.org/support/users/ritterml/)
 * (@ritterml)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/#post-15087101)
 * [@catacaustic](https://wordpress.org/support/users/catacaustic/) thanks for the
   tip.
 * This should be addressed though, because, as a developer adding to the theme 
   incrementally I have added the code in a template and it should be honored.
 * I should be able to add the menu through my template or functions so it is does
   not require end user to create.
 * Can you or an admin please post a response with the WordPress way to do this?
    -  This reply was modified 4 years, 6 months ago by [Mike Ritter](https://wordpress.org/support/users/ritterml/).
 *  [Mike Ritter](https://wordpress.org/support/users/ritterml/)
 * (@ritterml)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/#post-15087866)
 * **How to Avoid**
 * Thanks [@catacaustic](https://wordpress.org/support/users/catacaustic/) for starting
   me on the path to resolving this.
 * The solution is the parameter `fallback_cb`.
 * In your array, set this option to ‘false’ or ‘0’.
 *     ```
       <?php wp_nav_menu(['location'=>'header-menu','fallback_cb'=>'0']) ?>
       ```
   
 * See [https://developer.wordpress.org/reference/functions/wp_nav_menu/](https://developer.wordpress.org/reference/functions/wp_nav_menu/)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Using wp_nav_menu function to set classes’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 4 participants
 * Last reply from: [Mike Ritter](https://wordpress.org/support/users/ritterml/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/using-wp_nav_menu-function-to-set-classes/#post-15087866)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
