Display Menu Name using wp_nav_menu. 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.
1 2 3 4 5 6 7 8 9 10 11 12 | <?php 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; } ?> |
Then
1 2 3 4 5 6 7 8 | //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
:
1 2 3 4 | $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>') ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.