在管理中删除重复的主菜单-子菜单?

时间:2011-05-05 作者:JM at Work

当我使用add_menu_page &;add_submenu_page 要添加菜单项,

add_menu_page( \'Forms\', \'Forms\', \'administrator\', \'forms\', \'forms_job_menupage_cb\' );
add_submenu_page( \'forms\', \'Job Applications\', \'Job Applications\', \'administrator\', \'job-applications\', \'forms_job_menupage_cb\' );
add_submenu_page( \'forms\', \'Quote Requests\', \'Quote Requests\', \'administrator\', \'quote-req\', \'forms_req_menupage_cb\' );
add_submenu_page( \'forms\', \'Contact\', \'Contact\', \'administrator\', \'contact\', \'forms_contact_menupage_cb\' );
我会得到这样的东西

求职申请表是否可以创建为

表格求职申请表报价申请表联系人换句话说,表格将链接到求职申请表,我不需要额外的表格子菜单项

4 个回复
最合适的回答,由SO网友:MikeSchinkel 整理而成

你好@JM at Work:

是的,很遗憾,每个菜单页都添加了子菜单页。那太好了if there were an option but alas, there currently is not.

要删除WordPress 3.1中的子菜单页选项,请使用remove_submenu_page() 在主题的functions.php 文件,或在.php 您可能正在编写的插件的文件:

add_action( \'admin_menu\', \'yoursite_admin_menu\' );
function yoursite_admin_menu() {
  add_menu_page( \'Forms\', \'Forms\', \'administrator\', \'forms\', \'forms_job_menupage_cb\' );
  add_submenu_page( \'forms\', \'Job Applications\', \'Job Applications\', \'administrator\', \'job-applications\', \'forms_job_menupage_cb\' );
  add_submenu_page( \'forms\', \'Quote Requests\', \'Quote Requests\', \'administrator\', \'quote-req\', \'forms_req_menupage_cb\' );
  add_submenu_page( \'forms\', \'Contact\', \'Contact\', \'administrator\', \'contact\', \'forms_contact_menupage_cb\' );
  remove_submenu_page(\'forms\',\'forms\');
}
如果您仍在使用WordPress 3.0,则必须unset() 全局变量的元素$submenu 像这样:

add_action( \'admin_menu\', \'yoursite_admin_menu\' );
function yoursite_admin_menu() {
  add_menu_page( \'Forms\', \'Forms\', \'administrator\', \'forms\', \'forms_job_menupage_cb\' );
  add_submenu_page( \'forms\', \'Job Applications\', \'Job Applications\', \'administrator\', \'job-applications\', \'forms_job_menupage_cb\' );
  add_submenu_page( \'forms\', \'Quote Requests\', \'Quote Requests\', \'administrator\', \'quote-req\', \'forms_req_menupage_cb\' );
  add_submenu_page( \'forms\', \'Contact\', \'Contact\', \'administrator\', \'contact\', \'forms_contact_menupage_cb\' );
  unset($GLOBALS[\'submenu\'][\'forms\'][0]);
}

SO网友:Evgeniy Z.

指定与父菜单类似的第一个子菜单slug。在您的情况下,用主菜单“表单”的slug替换“工作申请”。

add_menu_page( \'Forms\', \'Forms\', \'administrator\', \'forms\', \'forms_job_menupage_cb\' );
add_submenu_page( \'forms\', \'Job Applications\', \'Job Applications\', \'administrator\', \'forms\', \'forms_job_menupage_cb\' );
add_submenu_page( \'forms\', \'Quote Requests\', \'Quote Requests\', \'administrator\', \'quote-req\', \'forms_req_menupage_cb\' );
add_submenu_page( \'forms\', \'Contact\', \'Contact\', \'administrator\', \'contact\', \'forms_contact_menupage_cb\' );

SO网友:Doug Cassidy

我必须添加\\u submenu\\u页面,然后将其删除(wp 4.0.1)

add_menu_page( \'Admin Tools\', \'Admin Tools\', \'manage_options\',\'parent\', \'__return_null\',\'\', "70.23423" );
    // this \'hides\' the extra.  actually, just makes the text nothing: \'\'  
    add_submenu_page( \'parent\', \'\',     \'\', \'manage_options\',   \'parent\',   \'__return_null\' );
    //ah, but this removes it completely (you need to add it, then remove it :/     
    remove_submenu_page(\'parent\',\'parent\');

SO网友:Sam Wilson

我建议保留额外的菜单项,因为这是所有其他WP菜单的工作方式。(我知道你不是这么问的!…)其他顶级菜单的工作方式是,它们对大菜单标题和下面的重复菜单标题有不同的标签(例如,“用户”、“所有用户”、“工具”、“可用工具”)。我认为坚持使用相同的范例是很好的,因此我通常将第一个子菜单项重命名为如下:

<?php
add_menu_page( \'Plugin Name\', \'Plugin Name\', \'read\', \'plugin-slug\', $callback );
add_submenu_page( \'plugin-slug\', \'Plugin Overview\', \'Overview\', \'read\', \'plugin-slug\', $callback );

结束

相关推荐