WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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?

share|improve this question
up vote 8 down vote accepted

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

share|improve this answer
    
Perfect. Thanks for the answer. – N2Mystic Aug 8 '11 at 18:12

Use has_nav_menu:

Returns boolean Whether a registered nav menu location has a menu assigned(true) or not(false).

<?php $menu=has_nav_menu( $location ); ?> 

Reference: has_nav_menu

share|improve this answer

Your Answer

 
discard

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.