Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Created March 13, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdavis/25d4a733b7c2754ca1e34db31a735bb0 to your computer and use it in GitHub Desktop.
Save nickdavis/25d4a733b7c2754ca1e34db31a735bb0 to your computer and use it in GitHub Desktop.
Get a WordPress menu from a specific menu location
<?php
/**
* Returns the menu object associated with a particular menu location.
*
* You could then get the slug of the menu, for example, via
* $menu_object->slug (or whatever variable you saved the menu object as).
*
* @param string $location_slug
*
* @return object
*/
function get_menu_from_location( $location_slug ) {
return get_term( get_nav_menu_locations()[$location_slug], 'nav_menu' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment