$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Hide parent link in submenu on admin menu|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Hide parent link in submenu on admin menu

matteradmin8PV0评论

I have the following code to display my admin menu, but I want to hide the CMC Intranet Tabs on the submenu. I know this is probably simple, but my Google-Fu is failing me today.

function newintranet_tabs_admin_menu_option() {
    add_menu_page('CMC Intranet Tabs', 'CMC Intranet Tabs', 'manage_options', 'newintranet_tabs_admin_menu', 'newintranet_tabs_scripts_page', '', 200);
    add_submenu_page('newintranet_tabs_admin_menu', 'Add Tabbed Page', 'Add Tabbed Page', 'manage_options', 'newintranet_add_tabbed_page', 'newintranet_add_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Edit Tabbed Page', 'Edit Tabbed Page', 'manage_options', 'newintranet_edit_tabbed_page', 'newintranet_edit_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Order Tabbed Pages', 'Order Tabbed Pages', 'manage_options', 'newintranet_order_tabbed_page', 'newintranet_order_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Delete Tabbed Page', 'Delete Tabbed Page', 'manage_options', 'newintranet_delete_tabbed_page', 'newintranet_delete_tabbed_page_page');
}
add_action('admin_menu', 'newintranet_tabs_admin_menu_option');

What I'm getting:

I have the following code to display my admin menu, but I want to hide the CMC Intranet Tabs on the submenu. I know this is probably simple, but my Google-Fu is failing me today.

function newintranet_tabs_admin_menu_option() {
    add_menu_page('CMC Intranet Tabs', 'CMC Intranet Tabs', 'manage_options', 'newintranet_tabs_admin_menu', 'newintranet_tabs_scripts_page', '', 200);
    add_submenu_page('newintranet_tabs_admin_menu', 'Add Tabbed Page', 'Add Tabbed Page', 'manage_options', 'newintranet_add_tabbed_page', 'newintranet_add_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Edit Tabbed Page', 'Edit Tabbed Page', 'manage_options', 'newintranet_edit_tabbed_page', 'newintranet_edit_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Order Tabbed Pages', 'Order Tabbed Pages', 'manage_options', 'newintranet_order_tabbed_page', 'newintranet_order_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Delete Tabbed Page', 'Delete Tabbed Page', 'manage_options', 'newintranet_delete_tabbed_page', 'newintranet_delete_tabbed_page_page');
}
add_action('admin_menu', 'newintranet_tabs_admin_menu_option');

What I'm getting:

Share Improve this question asked May 20 at 17:14 Darth Mikey DDarth Mikey D 1051 silver badge9 bronze badges 2
  • that's how submenus work, I can see why you'd want this due to the duplication, but perhaps the solution is to rename the submenu? Take the general settings page as an example, it is not a subpage of the top level "Settings" menu page, it is the top level "Settings" despite having a different name. You can rename it by registering a submenu with the same menu slug, letting you change its name to something more sensible – Tom J Nowell Commented May 20 at 18:09
  • Thanks for the reply. Can you give me an example of what you mean? I tried changing CMC Intranet Tabs to Add Tabbed Page in both locations, but it either changed both links or didn't do anything. – Darth Mikey D Commented May 20 at 18:41
Add a comment  | 

1 Answer 1

Reset to default 3

As @Tom J Nowell pointed out in the comments, using the same slug for the admin menu and the first submenu has the effect of removing the repeated menu name in the submenu.

function newintranet_tabs_admin_menu_option() {
    add_menu_page('CMC Intranet Tabs', 'CMC Intranet Tabs', 'manage_options', 'newintranet_tabs_admin_menu', 'newintranet_tabs_scripts_page', '', 200);
    add_submenu_page('newintranet_tabs_admin_menu', 'Add Tabbed Page', 'Add Tabbed Page', 'manage_options', 'newintranet_tabs_admin_menu', 'newintranet_add_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Edit Tabbed Page', 'Edit Tabbed Page', 'manage_options', 'newintranet_edit_tabbed_page', 'newintranet_edit_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Order Tabbed Pages', 'Order Tabbed Pages', 'manage_options', 'newintranet_order_tabbed_page', 'newintranet_order_tabbed_page_page');
    add_submenu_page('newintranet_tabs_admin_menu', 'Delete Tabbed Page', 'Delete Tabbed Page', 'manage_options', 'newintranet_delete_tabbed_page', 'newintranet_delete_tabbed_page_page');
}
add_action('admin_menu', 'newintranet_tabs_admin_menu_option');

Note that the 1st submenu's slug has been changed from newintranet_add_tabbed_page to newintranet_tabs_admin_menu.

I assume this is what you're looking for (ignore the colour scheme, that's just my local dev server).

Post a comment

comment list (0)

  1. No comments so far