WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
function wp_get_nav_menu_object( $menu ) {
if ( ! $menu )
    return false;

$menu_obj = get_term( $menu, 'nav_menu' );

if ( ! $menu_obj )
    $menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );

if ( ! $menu_obj )
    $menu_obj = get_term_by( 'name', $menu, 'nav_menu' );

if ( ! $menu_obj )
    $menu_obj = false;

return $menu_obj;

I know that has_nav_menu can be used to check if a nav menu has been assigned to a theme location however not sure what the code above does as the docs for this function are limited.

I need to check if the nav menu exists and the theme location is supported by the theme.

Code Source http://queryposts.com/function/wp_get_nav_menu_object/

share|improve this question

The answer is in the source code that you posted.

The code attempts to get the menu by ID using get_term, then by slug and name using get_term_by. If nothing is found it returns false, here:

if ( ! $menu_obj )
    $menu_obj = false;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.