has_nav_menu() WordPress Function

The has_nav_menu() function checks whether a location has a menu assigned to it. A menu can be assigned to a location by going to the Menus page in the Wordpress admin and selecting the location from the dropdown menu.

has_nav_menu( string $location ) #

Determines whether a registered nav menu location has a menu assigned to it.


Parameters

$location

(string)(Required)Menu location identifier.


Top ↑

Return

(bool) Whether location has a menu.


Top ↑

Source

File: wp-includes/nav-menu.php

function has_nav_menu( $location ) {
	$has_nav_menu = false;

	$registered_nav_menus = get_registered_nav_menus();
	if ( isset( $registered_nav_menus[ $location ] ) ) {
		$locations    = get_nav_menu_locations();
		$has_nav_menu = ! empty( $locations[ $location ] );
	}

	/**
	 * Filters whether a nav menu is assigned to the specified location.
	 *
	 * @since 4.3.0
	 *
	 * @param bool   $has_nav_menu Whether there is a menu assigned to a location.
	 * @param string $location     Menu location.
	 */
	return apply_filters( 'has_nav_menu', $has_nav_menu, $location );
}


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.