has_nav_menu

函式
has_nav_menu ( $location )
引數
  • (string) $location Menu location identifier.
    Required:
返回值
  • (bool) Whether location has a menu.
定義位置
相關方法
is_nav_menuwp_nav_menuis_nav_menu_itemregister_nav_menuwalk_nav_menu_tree
引入
3.0.0
棄用
-

has_nav_menu – 這是一個WordPress函式,用於檢查是否有一個特定的導航選單被註冊。導航選單是自定義選單,用於顯示網站上不同頁面或類別的連結。has_nav_menu函式接收一個引數,即選單的名稱,如果該選單已經被註冊,則返回true,如果沒有則返回false。

確定一個已註冊的導航選單位置是否有一個選單分配給它。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >