is_nav_menu() WordPress Function

The is_nav_menu() function checks whether a given menu location has a menu assigned to it.

is_nav_menu( int|string|WP_Term $menu ) #

Determines whether the given ID is a navigation menu.


Description

Returns true if it is; false otherwise.


Top ↑

Parameters

$menu

(int|string|WP_Term)(Required)Menu ID, slug, name, or object of menu to check.


Top ↑

Return

(bool) Whether the menu exists.


Top ↑

Source

File: wp-includes/nav-menu.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;
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.