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

I have created one new menu and add bellow code in footer.php to display my menu

wp_nav_menu( array('menu' => 'footer-cn', 'menu_id' => 'nav', 'menu_class' => 'ft-nav' ));

Currently I did not add any pages inside this menu so I want to set some condition if any pages available inside footer-cn then display menu.

I want to set condition something this:

    if(){ // Some condition
        wp_nav_menu( array('menu' => 'footer-cn', 'menu_id' => 'nav', 'menu_class' => 'ft-nav' ));

Is it possible?


enter image description here

share|improve this question
Short answer is "yes - absolutely". If you edit your question to include the condition details, you'll likely have a response with how to accomplish the condition test. – jdm2112 May 1 '14 at 5:03
up vote 2 down vote accepted

No need to use conditional here to hide your nav menu when it is empty.

Have a look at wp_nav_menu( $args );. It accepts the following arguments

$defaults = array(
    'theme_location'  => '',
    'menu'            => '',
    'container'       => 'div',
    'container_class' => '',
    'container_id'    => '',
    'menu_class'      => 'menu',
    'menu_id'         => '',
    'echo'            => true,
    'fallback_cb'     => 'wp_page_menu',
    'before'          => '',
    'after'           => '',
    'link_before'     => '',
    'link_after'      => '',
    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth'           => 0,
    'walker'          => ''

wp_nav_menu( $defaults );

The important one here is 'fallback_cb'

$fallback_cb (string) (optional)

If the menu doesn't exist, the fallback function to use. Set to false for no fallback. Note: Passes $args to the custom function.

Default: wp_page_menu

So to hide a menu when it is empty, you can simply just add this to your arguments

'fallback_cb' => false

So your end code should be

wp_nav_menu( array('menu' => 'footer-cn', 'menu_id' => 'nav', 'menu_class' => 'ft-nav',  'fallback_cb' => false));
share|improve this answer
Excellent. Thank you so much. :) – Mr.Happy May 1 '14 at 8:41
My pleasure, glad I could help – Pieter Goosen May 1 '14 at 8:46

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.