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 am using this code to call any custom menu and display:

wp_nav_menu( array( 
    'container' => 'none', 
    'container_class' => 'menu-header', 
    'theme_location' => 'primary', 
    'menu' => get_post_meta( $post->ID, 'MenuName', true) ) 
); ?>

At the moment if there is no custom menu defined it falls back to the primary menu.

I am trying to edit this code, so if there is no custom menu then display nothing. Having no luck, doesn't help that I'm new to php and wordpress. I have searched online and tried a few other solutions. Knowing my luck it's probably something really simple.

If anyone could help me out, I'd appreciate it a lot!


share|improve this question

Simply set it to a predefined core-function that returns null or false:

'fallback_cb'     => '__return_zero'
// or
'fallback_cb'     => '__return_false'
share|improve this answer
neat answer - thanks – Q Studio Oct 14 '12 at 11:53

the wp_nav_menu fallback is wp_page_menu() by default. you think you could change the fallback to a null string

'fallback_cb'     => '',

or you could first test for the presence of a menu?

if(has_nav_menu('primary')) wp_nav_menu('theme_location' => 'primary');

share|improve this answer
Thanks for the replies guys. kaiser, I tried using the fallback but that didn't seem to work. @helgatheviking, I couldn't quite figure out what to do with the if statement you posted :s Do I wrap my original code in the if statement? Apologies for silly questions. – jaffa786 Mar 13 '12 at 12:29
I figured it! This is the final code: <?php wp_nav_menu( array( 'container' => 'none', 'container_class' => 'menu-header', 'theme_location' => 'none', 'menu' => get_post_meta( $post->ID, 'MenuName', true), 'fallback_cb' => 'false' ) ); ?> thanks for the tips :) – jaffa786 Mar 13 '12 at 12:41
'fallback_cb' => 'false' simply deregisters any fallback. @helgatheviking +1 btw :) – kaiser Mar 13 '12 at 16:24
thanks kaiser, i learned something new from your answer re: __return_false . @jaffa786 - yes you could have wrapped your code w/ the IF statement – helgatheviking Mar 13 '12 at 17:07

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.