WordPress函数wp_create_nav_menu()

描述:

创建一个新的前台导航菜单

用法:

<?php $menu_id wp_create_nav_menu($menu_name?>

参数:

$menu_name

(string) (必填) 要创建的菜单名称

默认值: None

源文件:

// Check if the menu exists
$menu_name = 'My First Menu';
$menu_exists = wp_get_nav_menu_object( $menu_name );

// If it doesn't exist, let's create it.
if( !$menu_exists){
    $menu_id = wp_create_nav_menu($menu_name);

	// Set up default menu items
    wp_update_nav_menu_item($menu_id, 0, array(
        'menu-item-title' =>  __('Home'),
        'menu-item-classes' => 'home',
        'menu-item-url' => home_url( '/' ), 
        'menu-item-status' => 'publish'));

    wp_update_nav_menu_item($menu_id, 0, array(
        'menu-item-title' =>  __('Custom Page'),
        'menu-item-url' => home_url( '/custom/' ), 
        'menu-item-status' => 'publish'));

}