How to avoid creating first submenu page that is same as menu page?

I’ve created menu page and four submenu pages.

public function onixion_admin_menu_option() {
    add_menu_page('onixion','Onixion','manage_options','onixion-admin- 
    menu',array(&$this, 'onixion_main_page' ),'dashicons-chart- 
    area','200');
    add_submenu_page(
        'onixion-admin-menu', 
        'scripts',
        'Scripts', 
        'manage_options',
        'scripts',
        array(&$this, 'onixion_scripts_page' ) 
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'custom_footer',
        'Custom Footer', 
        'manage_options',
        'custom_footer',
        array(&$this, 'onixion_custom_footer_page' ) 
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'file_upload',
        'File Upload', 
        'manage_options',
        'file_upload',
        array(&$this, 'onixion_file_upload_page' ) 
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'payments',
        'Payments', 
        'manage_options',
        'payments',
        array(&$this, 'onixion_payments_page' ) 
    );
}   

Everything seems fine, there are those submenu pages with the text I printed to test them individually.

Onixion

The problem is that the first submenu page is a copy of menu page. What I want is to have different page when someone clicks on main menu option: ‘Onixion’ and to have only submenu pages I’ve added (Without ‘Onixion’ submenu page).

1 Answer
1

You can set slug of a subpage to be the same as slug of parent page. For example:

public function onixion_admin_menu_option() {
    add_menu_page('onixion',
        'Onixion',
        'manage_options',
        'onixion-admin-menu',
        array(&$this, 'onixion_main_page' ),
        'dashicons-chart-area',
        '200'
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'scripts',
        'Scripts', 
        'manage_options',
        'onixion-admin-menu',  // <-- here we set the same slug as for parent page
        array(&$this, 'onixion_scripts_page' ) 
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'custom_footer',
        'Custom Footer', 
        'manage_options',
        'custom_footer',
        array(&$this, 'onixion_custom_footer_page' ) 
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'file_upload',
        'File Upload', 
        'manage_options',
        'file_upload',
        array(&$this, 'onixion_file_upload_page' ) 
    );
    add_submenu_page(
        'onixion-admin-menu', 
        'payments',
        'Payments', 
        'manage_options',
        'payments',
        array(&$this, 'onixion_payments_page' ) 
    );
}   

Leave a Comment