If you check out has_nav_menu()
, you’ll see that it first checks if a menu exists for the location (what we expect).
However, it will also return true
if the location is merely registered, hence why your condition is still true even when there’s no menu:
function has_nav_menu( $location ) {
$registered_nav_menus = get_registered_nav_menus();
if ( ! isset( $registered_nav_menus[ $location ] ) ) {
return false;
}
$locations = get_nav_menu_locations();
return ( ! empty( $locations[ $location ] ) );
}
Instead, use the snippet from above to just check if an actual menu is registered:
$registered_nav_menus = get_registered_nav_menus();
if ( isset( $registered_nav_menus[ 'header-top' ] ) ) {
// Your nav menu
} else {
// No menu
}
Update: To check a valid menu exists & has items, use echo => false
and check the output:
$menu = wp_nav_menu(
array(
'theme_location' => 'header-top',
'container' => 'nav',
'menu_class' => 'right no-bullets no-margin',
'fallback_cb' => false,
'echo' => false,
)
);
if ( $menu ) {
echo $menu;
} else {
echo 'No menu!';
}