Support » Plugins and Hacks » Hacks » Plugin Menu Naming

  • Hi folks,

    I hope this is a simple question to answer. First, let me give some brief context before asking the question.

    The built-in WordPress admin menus function in a way that the main menu title points to the first submenu item. An example is the Settings menu. When you click on the Settings menu, it displays the General Settings page and highlights the first submenu item entitled “General.” Visually, this is what I am talking about (the menu items are displayed in bold below):

    – General

    – Writing
    – Reading

    I want to achieve this same functionality with my plugin menu, but my first submenu item is the same name as the entire plugin menu. How do I change it? Below is a visual representation of the results I see:

    – Custom

    – Misc. Settings

    The code I am using is found below:

    function custom_plugin_menu()
    	add_menu_page('Custom', 'Custom', 'manage_options', 'custom-plugin', 'custom_option_page');
    	add_submenu_page('custom-plugin','Misc. Settings', 'Misc. Settings', 'manage_options', 'custom-plugin2', 'custom_option_page2');
    add_action('admin_menu', 'custom_plugin_menu');

    Thanks for any help in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    I’m not sure why it’s done that way, but you can remove the Custom submenu by adding this to your action hook function:
    remove_submenu_page( 'custom-plugin', 'custom-plugin' );

    The answer is in the codex:

    (string) (required) The slug name to refer to this menu by (should be unique for this menu). If you want to NOT duplicate the parent menu item, you need to set the name of the $menu_slug exactly the same as the parent slug.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin Menu Naming’ is closed to new replies.