Get Menu By Location
Useful WordPress function to get a menu object from a given location.
Copy the following code into your functions.php
<?php
/**
* Get Menu By Location
* @param string $theme_location Theme location
* @return mixed Menu Object or false if not found
*/
if ( ! function_exists( 'get_menu_by_location' ) ):
function get_menu_by_location( $theme_location ) {
$theme_locations = get_nav_menu_locations();
$menu_obj = get_term( $theme_locations[ $theme_location ], 'nav_menu' );
if ( $menu_obj )
return wp_get_nav_menu_items( $menu_obj->term_id, $args );
else
return $menu_obj;
}
endif;
?>
Written by Etienne Tremel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Menu
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#