Adding class to menu_class to wp_nav_menu adds class to div instead of ul

I am very new to wordpress themeing . I am trying to create a Twitter Bootstrap menu to my newly created theme as below in header.php page.

$defaults = array(
                'theme_location'  => 'header-menu',
                'menu'            => '',
                'container'       => '',
                'container_class' => '',
                'container_id'    => '',
                'menu_class'      => 'navbar-collapse collapse',
                'menu_id'         => 'navbar',
                'echo'            => true,
                'fallback_cb'     => 'wp_page_menu',
                'before'          => '',
                'after'           => '',
                'link_before'     => '',
                'link_after'      => '',
                'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
                'depth'           => 0,
                'walker'          => ''
            );

        wp_nav_menu( $defaults );

With the above codes, I am expecting to add a class to navbar-collapse collapse to ul , but instead it produces HTML as below :

<div class="navbar-collapse collapse"><ul><li class="page_item page-item-11"> etc. How can I add class ul ?

Solutions

Try checking out a function that's already been made like this one. It will create the correct syntax for the menu to work.

Check you've actually registered 'header-menu' via register_nav_menus. Removing theme_location => 'header-menu' will resolve the issue until you've registered your navigation ID correctly.

You should have this in your functions.php

register_nav_menus( array(
    'header-menu' => __( 'Header Menu', 'domain' ),
) );

Similar questions

Wordpress do_shortcode with content and shortcodes inside adds shortcode before the content instead of inline
It seems that do_shortcode() (as well as apply_filters()) adds shortcodes in front of the content instead of inline. How could I go about solving this? To explain: I'm calling something like this inside my post: My functions.php contains this: Some text that needs to be displayed *before* the called list. Some text that needs to be displayed *after...
Wordpress: Customising output of wp_nav_menu, adding a div before nested ul
I'm building a site which uses a mega drop-down style menu which is styled using containing divs around the nested ul of the sub-menu. Does anybody know how to customise the output of the menu generated by Wordpress (wp_nav_menu) to add containing divs around the nested sub-menu ul? There are two parameters which are 'before' => '', 'after' => '', ...
Word press adds <div id="level-access-access-assistant-highlight-container">
I am using the Advanced Custom fields plugin in wordpress, and whenever I modify text fields on posts in chrome, wordpress appends <div id="level-access-access-assistant-highlight-container"> to the end of my text. Doesn't really do anything except pop up as a lighthouse error telling me I have multiple elements with the same id. Issue comes ...
Wordpress automatically adds <div> and <p> between widgets areas, how to avoid it?
So I have had to edit some code of the template I am using because I need two widget areas in the header, I have managed to achieve it, but the problem comes when Wordpress adds <div> and <p> between them and I do not want that because I need them in the same line, not in two lines. This is what I have done so far: Inside the file funct...
Using string instead of object class instantiation on the walker argument breaks wp_nav_menu
I'm trying to replace the walker argument from new My_Walker_Nav_Menu() to a string 'My_Walker_Nav_Menu' in this wp_nav_menu call (which works as is) When I change it to a string I'm getting this error Fatal error: Using $this when not in object context The class is basic: I need to do this because apparently Customizer's partial refresh doesn't wo...
How to remove containing div and add a class to ul using wp_nav_menu()?
I want to generate this markup: From reading the wordpress function reference for the wp_nav_menu function i think i should be calling this: But when i run that, i get the following: What am I doing wrong?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .