Home / functions.php / Get assigned menu location with get_nav_menu_locations
  • Get assigned menu location with get_nav_menu_locations

    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.

    wordpress snippet : PHP

    <>
    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;
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    _n, has_nav_menu, wp,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks