WordPress at a glance

has_nav_menu() WP 1.0

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

Works based on: get_nav_menu_locations()
Hooks from function:
Return

true/false. Whether location has a menu.

Usage

has_nav_menu( $location );
$location(string) (required)
Menu location identifier.

Code of has_nav_menu: wp-includes/nav-menu.php VER 4.9.8

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

Related Functions

From tag: nav menu (nav_menu)

More from tag: Conditional tags (all)

More from category: Menu

No comments
    Hello, !     Log In . Register