plugins - How to remove admin main menu name repetition

I have added an admin menu using add_menu_page. When there is a sub menu with add_submenu_page,The main menu name is rep

I have added an admin menu using add_menu_page. When there is a sub menu with add_submenu_page,

The main menu name is repeating. How to remove this repeating menu ?

This is my code

add_action('admin_menu', 'add_my_menu');
function add_my_menu(){
    add_menu_page( 'Main Menu', 'Main Menu', 'manage_options', 'main-menu-settings', 'main_menu_settings');
    add_submenu_page( 'main-menu-settings', 'Sub Menu', 'sub menu', 'manage_options', 'sub-menu', 'sub_menu_settings');
}

I have added an admin menu using add_menu_page. When there is a sub menu with add_submenu_page,

The main menu name is repeating. How to remove this repeating menu ?

This is my code

add_action('admin_menu', 'add_my_menu');
function add_my_menu(){
    add_menu_page( 'Main Menu', 'Main Menu', 'manage_options', 'main-menu-settings', 'main_menu_settings');
    add_submenu_page( 'main-menu-settings', 'Sub Menu', 'sub menu', 'manage_options', 'sub-menu', 'sub_menu_settings');
}
Share Improve this question edited Jul 3, 2014 at 6:21 Dinoop asked Jul 2, 2014 at 12:07 DinoopDinoop 1113 bronze badges 1
  • 1 Please add your code to the question for easily reproducible example. – Rarst Commented Jul 2, 2014 at 12:14
Add a comment  | 

1 Answer 1

Reset to default 0

You can remove it from the submenu array:

function add_my_menu(){
    global $submenu;
    add_menu_page( 'Main Menu', 'Main Menu', 'manage_options', 'main-menu-settings', 'main_menu_settings');
    add_submenu_page( 'main-menu-settings', 'Sub Menu', 'sub menu', 'manage_options', 'sub-menu', 'sub_menu_settings');
    unset( $submenu['main-menu-settings'][0] );
}

The parent item is added by add_submenu_page in plugin.php as the first link if the parent doesn't already have a submenu, resulting in:

[main-menu-settings] => Array
    (
        [0] => Array
            (
                [0] => Main Menu
                [1] => manage_options
                [2] => main-menu-settings
                [3] => Main Menu
                [4] => menu-top menu-icon-generic toplevel_page_main-menu-settings
                [5] => toplevel_page_main-menu-settings
                [6] => dashicons-admin-generic
            )
        [1] => Array
            (
                [0] => sub menu
                [1] => manage_options
                [2] => sub-menu
                [3] => Sub Menu
            )
    )

being added to $submenu.

I assume that UI decision is along the lines of Don't Make Me Think. All the menu links are grouped in the same place so the user doesn't have to remember to click the parent link in the sidebar to go to the main page for that section. So the primary purpose of that parent link in the sidebar is to open the submenu.

If the user is hovering over the submenu trying to determine which page to go to, and the main page is not listed, they might not think to click on the parent link in the sidebar.

Since every other WordPress menu works that way, consider leaving it as is.

Another option is to make it more descriptive.

global $submenu;
$submenu['main-menu-settings'][0][0] = "My Plugin Main Menu";

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745269024a4619631.html

相关推荐

  • plugins - How to remove admin main menu name repetition

    I have added an admin menu using add_menu_page. When there is a sub menu with add_submenu_page,The main menu name is rep

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信