How do I get the name of a menu in WordPress?

You can access the menu metadata using the wp_get_nav_menu_object function

BY NAME:

$menu = wp_get_nav_menu_object("my mainmenu" );

BY SLUG:

$menu = wp_get_nav_menu_object("my-mainmenu" );

The return object as follows:

 Object (
   term_id => 4
   name => My Menu Name
   slug => my-menu-name
   term_group => 0
   term_taxonomy_id => 4
   taxonomy => nav_menu
   description => 
   parent => 0
   count => 6
 )

To display the name:

echo $menu->name;

Leave a Comment