WordPress.org

Ready to get started?Download WordPress

Forums

Plugin Menu Naming (3 posts)

  1. doolezah
    Member
    Posted 1 year ago #

    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):

    Settings
    - 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
    - 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!

  2. bcworkz
    Member
    Posted 1 year ago #

    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' );

  3. AntoineH
    Member
    Posted 1 year ago #

    The answer is in the codex: http://codex.wordpress.org/Function_Reference/add_submenu_page

    $menu_slug
    (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.

Topic Closed

This topic has been closed to new replies.

About this Topic