函数原型
has_nav_menu( string $location ): bool
函数描述
Determines whether a registered nav menu location has a menu assigned to it.
是否弃用
未弃用
函数参数
-
$location
string
Required - Menu location identifier.
函数返回值
bool Whether location has a menu.
函数位置
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |

