Been struggling with this for a little while. I want to call a menu but include the title of the menu above the menu list. The basic code I have is as follows –
<?php wp_nav_menu( array(
'container' => 'div',
'container_class' => 'rmm-footer',
'theme_location' => 'resources'
));
?>
This produces a list as follows –
Menu Item 1
Menu Item 2
Menu Item 3
But I want it to go as follows –
TITLE
Menu Item 1
Menu Item 2
Menu Item 3
Anyone got any ideas?
Thanks in advance.
You can not get the menu title using wp_nav_menu()
, you need to get the menu object as follow:
//Change with the ID of your menu
$menu_ID = 5;
$nav_menu = wp_get_nav_menu_object( $menu_ID );
// then echo the name of the menu
echo $nav_menu->name;
With the above code, you can insert the menu name in wp_nav_menu()
using items_wrap
parameter. For example:
$menu_ID = 5;
$nav_menu = wp_get_nav_menu_object( $menu_ID );
wp_nav_menu( array(
'theme_location' => 'resources',
'container' => 'div',
'container_class' => 'rmm-footer',
'items_wrap' => '<ul><li id="item-id">'.$nav_menu->name.'</li>%3$s</ul>'
)
);