Do you want to get the name of an assigned menu based on the location name? While menu settings can be managed in appearance settings, we have created a quick code snippet that you can use to get assigned menu location with get_nav_menu_locations
in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
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; }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: How to set up author tracking in WordPress with Google Analytic and 15 best content marketing tools.
Not doing anything for me. Just getting a white page now.