Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using this code to call any custom menu and display:

<?php 
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!

Thanks

share|improve this question
add comment

2 Answers

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
add comment

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
1  
neat answer - thanks –  Q Studio Oct 14 '12 at 11:53
add comment

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.