WordPress at a glance

is_nav_menu() WP 1.0

Check if the given ID is a navigation menu.

Returns true if it is; false otherwise.

Works based on: wp_get_nav_menu_object()
✈ 1 time = 0.004447s = very slow | 50000 times = 7.98s = 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-includes/nav-menu.php WP 5.2.4

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

Related Functions

From tag: nav menu (nav_menu)

More from tag: Conditional tags (all)

More from category: Menu

No comments
    Hello, !     Log In . Register