Admin Menu – Highlight top-level menu when on a sub-menu page (without showing sub-menu)

That’s a bit of a late answer and I don’t know if @Jay ever sorted it out, but to anyone having the same issue, here’s how I fixed it.

Menu Pages

function my_admin_menu() {

    add_menu_page(
        'Page title',
        'Menu title',
        'manage_options',
        'my_page',
        null,
        null,
        99
    ); 

    add_submenu_page(
        'my_page',
        'Subpage 1 title',
        'Subpage 1 menu title',
        'manage_options',
        'my_subpage_1',
        null
    );

    add_submenu_page(
        'my_page',
        'Subpage 2 title',
        'Subpage 2 menu title',
        'manage_options',
        'my_subpage_2',
        null
    );
}
add_action( 'admin_menu', 'my_admin_menu' ) );

function my_admin_head() {

    remove_submenu_page( 'my_page', 'my_subpage_1' );
}
add_action( 'admin_head', 'my_admin_head' );

See the Codex for remove_submenu_page.

Leave a Comment