function “add_submenu_page in wordpress connects to the home page instead of the submenu page

It may be because you are using the same name of the slug in the name of the callback function, try changing it.

You can also do the following:

add_submenu_page(
    'bbtb_conventions',
    'Settings',
    'Settings',
    'manage_options',
    'bbtb_settings',
    'bbtb_settings_callback'
);

function bbtb_settings_callback() {
    include "includes/setting_page.php";
}

You can even omit the callback function with an anonymous one.

add_submenu_page(
    'bbtb_conventions',
    'Settings',
    'Settings',
    'manage_options',
    'bbtb_settings',
    function () { // anonymous callback function
        include "includes/setting_page.php";
    }
);

There is also no need to add a conditional to verify the capacity of manage_options, because for something the capacity is set in parameter 3 in add_menu_page() and in parameter 4 in add_submenu_page()

I hope I have helped you, greetings!

Leave a Comment