Admin Menus – Name Menu different from first Submenu

I am creating a submenu with the following code:

add_action( 'admin_menu', 'jp_create_admin_pages' );

function jp_create_admin_pages()
{
    add_menu_page(
        'Members',
        'Members',
        'manage_options',
        'members',
        'jp_handle_admin_members');

    add_submenu_page(
        'members',
        'Membership Types',
        'Membership Types',
        'manage_options',
        'jp_handle_admin_membership_types');
}

This creates a custom menu called ‘Members’ with two sub-menus: ‘Members’ and ‘Membership Types’.

Read More

I want to make it so that the first submenu is called ‘All Members’ instead of ‘Members’ (to mirror the built in menu types). Any ideas?

Related posts

2 comments

  1. The first menu item typically is the parent item and shares the name with that item, you can however manually update the entry directly in the $submenu variable, like so..

    add_action( 'admin_menu', 'jp_create_admin_pages' );
    
    function jp_create_admin_pages() {
        global $submenu;
        add_menu_page('Members','Members','manage_options','members','jp_handle_admin_members');
        add_submenu_page('members','Membership Types','Membership Types','manage_options','membership_types','jp_handle_admin_membership_types');
        $submenu['members'][0][0] = 'All Members';
    }
    

    That way your parent keeps the original name, whilst the first subitem has another.

    Hope that helps.

  2. Have you tried changing the Menu title to ‘All Membership Types’?

    add_submenu_page(
            'members',
            'Membership Types',
            'All Membership Types',
            'manage_options',
            'jp_handle_admin_membership_types');
    

    http://codex.wordpress.org/Function_Reference/add_submenu_page

    Not sure if it’s possible to do it any other way.

    I know what you are trying to achieve, like when registering a custom post type. There is actually a field for All Items that’s built into the labels array.

Comments are closed.