wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Get assigned menu location with get_nav_menu_locations

wordpress snippet

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.

snippet :  PHPcopy
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;

Did you like this post? If so please share it with your friends. Thanks!