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/


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;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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