register_nav_menu()注册一个前台导航菜单

目录

描述

Registers a single custom Navigation Menu in the custom menu editor (in WordPress 3.0 and above). This allows administration users to create custom menus for use in a theme.

See register_nav_menus() for creating multiple menus at once.

register_nav_menu() 描述

用法

 <?php register_nav_menu$location$description ); ?> 

register_nav_menu() 用法

参数

$location

(string) (必填) Menu location identifier, like a slug.

默认值: None

$description

(string) (必填) Menu description - for identifying the menu in the dashboard.

默认值: None

register_nav_menu() 参数

返回值

None.

register_nav_menu() 返回值

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
  register_nav_menu( 'primary', __( 'Primary Menu', 'theme-slug' ) );
}
?>

register_nav_menu() 示例

注意

  • This function automatically registers custom menu support for the theme therefore you do not need to call add_theme_support( 'menus' );
  • This function actually works by simply calling register_nav_menus() in the following way:
    /* ----------------------------------
     * wordpress之魂 © http://wphun.com
     * ---------------------------------- */
    register_nav_menus( array( $location => $description ) );
  • Use wp_nav_menu() to display your custom menu.

register_nav_menu() 注意

历史

  • 添加于 版本: 3.0.0

register_nav_menu() 历史

源文件

register_nav_menu() 函数的代码位于 wp-includes/nav-menu.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Register a navigation menu for a theme.
 *
 * @since 3.0.0
 *
 * @param string $location    Menu location identifier, like a slug.
 * @param string $description Menu location descriptive text.
 */
function register_nav_menu( $location, $description ) {
	register_nav_menus( array( $location => $description ) );
}

register_nav_menu() 源文件

相关