I need to add a title to my menu, which is being built by wp_nav_menu...something like this:
<div class="container">
<div class="title">My Menu Title</div>
<ul class="menu">
<li class="item"><a href="#">Item 1</a></li>
<li class="item"><a href="#">Item 2</a></li>
<li class="item"><a href="#">Item 3</a></li>
</ul>
</div>
I find it strange that this isn't included by default :s
Click on any of your menu items. You will see a text box for Title Attribute. Fill out the text box and repeat these steps for every navigation menu item. Once you have updated all of your navigation items click on the “Save Menu” button.
Optionally, you may want to add the option to add classes to list items: function add_menu_list_item_class($classes, $item, $args) { if (property_exists($args, 'list_item_class')) { $classes[] = $args->list_item_class; } return $classes; } add_filter('nav_menu_css_class', 'add_menu_list_item_class', 1, 3);
This should work for you!
wp_nav_menu(
array(
'items_wrap' => '<div class="title">Your menu title</div><ul class="%2$s">%3$s</ul>'
)
);
This seems like a slightly broken option, I followed the guide on the wordpress codex, and a linked recommended guide, and every time, items_wrap did nothing at all, my original menu code was
<?php wp_nav_menu( array( 'theme_location' => 'primary','items_wrap' => '<ul id="%1$s" class="sf-menu %2$s">%3$s</ul>' ) ); ?>
Which didn't work and after much hair pulling, I changed to this
<?php wp_nav_menu( array( 'items_wrap' => '<ul class="sf-menu %2$s">%3$s</ul>' ) ); ?>
Which does, both are basically identical, so if it doesn't work first time don't give up, strip back and keep trying!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With