Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the menu name of a menu in wordpress

Tags:

wordpress

I have created a menu with the name "alggemeen" and added some items to it.

enter image description here

I have assigned the menu to the theme location Footer menu with the slug 'footer-menu'.

enter image description here

Now I know how to display the content of menu and also the menu_location. But I want to display the name the wordpress admin will provide in backend for the menu, on my website.

I would like to echo the name of the menu that has been allocated to the menu with a theme location of 'Footer Menu(slug = 'footer-menu')'.

So as shown above in the picture Currently alggemeen is the menu assigned to Footer Menu so my front end should echo algemeen.

like image 500
Kiran Dash Avatar asked Sep 18 '15 09:09

Kiran Dash


1 Answers

Try this code :

$menu_location = 'header';

$menu_locations = get_nav_menu_locations();

$menu_object = (isset($menu_locations[$menu_location]) ? wp_get_nav_menu_object($menu_locations[$menu_location]) : null);

$menu_name = (isset($menu_object->name) ? $menu_object->name : '');

echo esc_html($menu_name);
like image 135
Kundan Sharma Avatar answered Sep 27 '22 02:09

Kundan Sharma