2

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

0

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' ) 
    );
}   
  • Thanks for your answer, it removes the 'Onixion' submenu option, but when someone clicks on Onixion menu option, it redirects automatically to the first submenu option (in this case: Scripts). What I wanted 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). – Срђан Станишић Oct 5 '18 at 11:04
  • I’m afraid that is not possible. If menu has subpages, then one of these pages has to be active after clicking on parent - that’s how admin menu works. – Krzysiek Dróżdż Oct 5 '18 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.