管理菜单:使用ADD_MENU_PAGE和ADD_SUBMENU_PAGE对主题设置使用默认的“常规”页面

时间:2018-01-15 作者:neoDev

如何使我的主题设置管理菜单显示“常规”作为默认页面,同时将其菜单标题保持为“主题设置”?

我是说现在我用add_menu_pageadd_submenu_page:

enter image description here

但我想要“将军”。。。我正在努力想办法。。。这不可能吗?

1 个回复
SO网友:cweber105

您需要使用与菜单页相同的slug创建一个子菜单页。E、 g。

$menu_slug = "my_menu_slug";
$desired_capability = "manage_options"; //Or whatever you need
$menu_page_callback = "menu_page_callback_function";

add_menu_page(
    "Page Title", 
    "Menu Title", 
    $desired_capability, 
    $menu_slug, 
    $menu_page_callback
);

add_submenu_page(
    $menu_slug, 
    "Submenu Page Title", 
    "Submenu Menu Title",
    $desired_capability, 
    $menu_slug, 
    $menu_page_callback
);
//Note, the 5th and 6th parameters here are the same as above. This 
//overrides the first submenu title. Now clicking the 
//menu title and the first submenu item will navigate to the same page, 
//generated by the menu_page_callback function.

结束

相关推荐