Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom menu that I can call just fine using wp_nav_menu. Is there a way to have the menu name displayed inside an h3 tag before the menu?


<h3>My Menu Name</h3>
<li>Menu Item 1</li>
<li>Menu Item 2</li>
share|improve this question

3 Answers 3

up vote 8 down vote accepted

If you know the menu's slug, then things are easier, otherwise you can use this function to get the menu at a specified location.

function wpse45700_get_menu_by_location( $location ) {
    if( empty($location) ) return false;

    $locations = get_nav_menu_locations();
    if( ! isset( $locations[$location] ) ) return false;

    $menu_obj = get_term( $locations[$location], 'nav_menu' );

    return $menu_obj;


//if you after the menu the menu with a specific ID / Slug
//$menu_obj =wp_get_nav_menu_object($id_slug_or_name); 

//if you after the menu at a specific location
$menu_obj = wpse45700_get_menu_by_location($location); 

echo "<h3>".esc_html($menu_obj->name)."</h3>";
//Display menu here

Or, rather than echo the html, you could pass it as part of the the argument for the items attribute in wp_nav_menu.

For example, to display the menu at location 'primary':

$location = 'primary';
$menu_obj = wpse45700_get_menu_by_location($location ); 
wp_nav_menu( array('theme_location' => $location, 'items_wrap'=> '<h3>'.esc_html($menu_obj->name).'</h3><ul id=\"%1$s\" class=\"%2$s\">%3$s</ul>') ); 
share|improve this answer
Stephen, thanks for the great response. Sorry to be a noob but could you provide code for passing the html as an argument. That would solve everything. Thanks! – csi Mar 15 '12 at 18:02
See updated answer :D – Stephen Harris Mar 15 '12 at 18:18

replace the id 4 below with the id of your menu. if you don't know the id go into the menus page of the admin, right click on the tab of the menu you want to echo the title for, inspect elemenent and the id will be listed as menu=ID in the link.

$_menu_object = wp_get_nav_menu_object( 4 );
$nav_menu_selected_title = $_menu_object->name;
echo $nav_menu_selected_title;
share|improve this answer

stephen's answer is good. but i put it one step further:

$location = 'footer_navigation3';
if (has_nav_menu($location)) :
    $menu_obj = get_menu_by_location($location); 
    wp_nav_menu( array( 
        'theme_location'  => $location,
        'items_wrap'=> '<strong>'.esc_html($menu_obj->name).'</strong><ul id="%1$s" class="%2$s">%3$s</ul>'

assuming you have a registered a theme location called "footer_navigation3" and assigned a wp menu to that. now place this code where ever you want to display your menu.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.