is_nav_menu()WP 3.0.0

Check if the given ID is a navigation menu.

Returns true if it is; false otherwise.

1 time — 0.004447 sec (very slow) | 50000 times — 7.98 sec (fast) | PHP 7.2.5, WP 4.9.8

No Hooks.

Return

true|false. Whether the menu exists.

Usage

is_nav_menu( $menu );
$menu(int|string|WP_Term) (required)
Menu ID, slug, name, or object of menu to check.

Examples

0

#1 Check the custom menu for existence

$menu = 'menyu-s-rubrikami';       // menu slug 
// $menu = 41;                     // or menu ID
// $menu = 'Menu with categories'; // or menu name

if( is_nav_menu( $menu ) ){
	echo 'This menu exists';
}

Changelog

Since 3.0.0 Introduced.

is_nav_menu() code WP 6.6.2

function is_nav_menu( $menu ) {
	if ( ! $menu ) {
		return false;
	}

	$menu_obj = wp_get_nav_menu_object( $menu );

	if (
		$menu_obj &&
		! is_wp_error( $menu_obj ) &&
		! empty( $menu_obj->taxonomy ) &&
		'nav_menu' === $menu_obj->taxonomy
	) {
		return true;
	}

	return false;
}