has_nav_menu() - WordPress 函数参考中文文档

返回介绍

has_nav_menu()

发布于 2017-09-11 字数2137 浏览 928 评论 0

has_nav_menu( string $location )

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 描述
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/nav-menu.php:
    has_nav_menu
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/nav-menu.php:
    get_registered_nav_menus()
  • wp-includes/nav-menu.php:
    get_nav_menu_locations()

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    
    if ( has_nav_menu( 'primary' ) ) {
    	wp_nav_menu( array( 'theme_location' => 'primary' ) );
    }
    

上一篇:has_meta()

下一篇:has_post_format()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!