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


11

当我使用add_menu_pageadd_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' );

我会得到类似

  • 形式
    • 形式
    • 工作申请
    • 报价请求
    • 联络人

是否有可能创建它成为

  • 形式
    • 工作申请
    • 报价请求
    • 联络人

换句话说,表单将链接到求职申请,我不希望多余的表单子菜单项

Answers:


10

@JM,您好

是的,不幸的是,为每个菜单页面添加了子菜单页面。这将是很好,如果有一个选项,但很可惜,目前还没有

要删除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]);
}

非常感谢........... :)
Ridwan Pujakesuma

1

我必须add_submenu_page,然后将其删除(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');

1

我建议保留额外的菜单项,因为这是所有其他WP菜单的工作方式。(我知道这不是您要的!!)其他顶级菜单的工作方式是,它们在大菜单标题和其下的重复菜单上具有不同的标签(例如'Users','All Users'; “工具”,“可用工具”)。我认为最好使用相同的范例,因此我通常将第一个子菜单项重命名为:

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

1

分配与子菜单类似的第一个子菜单项。在您的情况下,将“ job-applications”替换为主菜单“ forms”的子弹。

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' );
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.