WordPress at Your Fingertips

is_nav_menu() WP 1.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.

Changelog

Since 3.0.0 Introduced.

Code of is_nav_menu() WP 5.8.1

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;
}

nav menu (nav_menu)

Conditional tags (all)

Menu

No comments
    Log In