1642 posts
  • Elite Author
  • Featured Author
  • 6 Years of Membership
  • Author Level 10
+8 more
fuelthemes
says

I don’t know why but some of the wordpress menus always seem to display all pages if you have not assigned any menu to them.

Is there a way to prevent this behavior? Display nothing if no menu is assigned?

461 posts Don't be a HATER!
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
  • Featured Author
+6 more
CodeElite
says

I use my own function to detect if user have create the menu or not

function wip_have_custom_menu( $loc ){
    $locations = get_nav_menu_locations();
    $menu = "";
    if( isset( $locations[ $loc ] ) ) {
        $menu = wp_get_nav_menu_object( $locations[ $loc ] );
    }

    if($menu)
        return true;
    else
        return false;
}

use it in the file, eg the theme location is ‘primary’

if ( !wip_have_custom_menu('primary') ):
//echo some message, so user can create the menu
else:
    $nav_args = array(
        'container'       => '', 
        'menu_class'      => 'menu', 
        'menu_id'         => 'eqnav',
        'echo'            => true,
        'depth'           => 0,
        'theme_location'  => 'primary'
    );
    wp_nav_menu($nav_args);    
endif;

hope it help :)

good luck

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 more
sevenspark
Moderator
says

The wp_nav_menu function has fallback functionality built in. You can assign any function you want via the fallback_cb parameter. You can set it to false to disable the fallback. I assume that would print nothing :)

http://codex.wordpress.org/Function_Reference/wp_nav_menu#Parameters
1642 posts
  • Elite Author
  • Featured Author
  • 6 Years of Membership
  • Author Level 10
+8 more
fuelthemes
says

I think I was looking for this function:

http://codex.wordpress.org/Function_Reference/has_nav_menu
by
by
by
by
by
by