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' ),
) );