1352 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has been part of the Envato Community for over 5 years
  • Has sold $250,000+ on Envato Market
+6 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?

448 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels 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

3446 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 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
1352 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has been part of the Envato Community for over 5 years
  • Has sold $250,000+ on Envato Market
+6 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