wordpresssettingscustom-pages

Wordpress - Add Settings Page to own Menu Page


Is it possible to add a single settings page to your own created menu page?
I have a Menu Page called "Company Menu". Inside this page I want to add a Settings page for the Social Media addresses of the Company, so the moderators can change/edit the social media addresses and add more if needed. Those settings should be used page-wide / globally.

Right now I do the following:

function company_register_menu() {
    add_menu_page( __( 'Company Menu', 'company' ), __( 'Company', 'company' ), 'edit_others_posts', 'company_menu', '', '', 4 );
}
add_action( 'admin_menu', 'company_register_menu' );  

Can I somehow do:

add_options_page()  

to create an options page inside this menu?


Solution

  • You have to use add_submenu_page to add submenu page in custom menu page.

    Please check the below line of code.

    function company_register_menu() {
        add_menu_page( __( 'Company Menu', 'company' ), __( 'Company', 'company' ), 'edit_others_posts', 'company_menu', '', '', 4 );
        add_submenu_page( 'company_menu', 'Social Media Addresses', 'Social Media Addresses', 'manage_options', 'social_media_addresses', '_social_media_addresses_function');
    }
    add_action( 'admin_menu', 'company_register_menu' );