Get assigned menu location with get_nav_menu_locations

Adding this snippet to the functions.php of your wordpress theme will let you get the name of an assigned menu based on the location name. Returns false if the defined location has no menu assigned. Useful for assigning titles to menus.



function mf_get_menu_name($location){
if(!has_nav_menu($location)) return false;
$menus = get_nav_menu_locations();
$menu_title = wp_get_nav_menu_object($menus[$location])->name;
return $menu_title;

Leave a comment