How to determine if custom menu is active?

My theme registers custom menus with this function:

function nav_menus() {
    if ( function_exists( 'register_nav_menus' ) ) {
      register_nav_menus(
        array('main-menu' => __( 'Main Menu' ), 'sub-menu' => __( 'Sub Menu' ))
      );
    }
}

I need to place code into my sidebar, that checks to see if the “main-menu” is active – for example, has a menu assigned to the “Main Menu” theme location.

Anyone know how to test for this?

2 Answers
2

You can use the function has_nav_menu('main-menu'). See the WordPress Codex here.

Leave a Comment