wp_nav_menu and fallback

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.

Read More

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

Related posts

Leave a Reply

2 comments

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

    'fallback_cb'     => '__return_zero'
    // or
    'fallback_cb'     => '__return_false'
    
  2. 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’);