note: updated the code with suggested code
I am creating a menu and submenu in the wordpress admin for a plugin. The menu item of the main menu works fine and goes to the right php file(page). but the submenu shows the text of the menu but when clicked on it it redirects to the 404 page and in my case it will go to the homepage. I have spend some hours over the code and it looks like I am overseeing something. Here is the code:
class BbtbPlugin{
public function __construct(){
add_action( 'init', array( $this,'bbtb_admin_menu' ));
}
public function bbtb_admin_menu() {
add_menu_page(
'Bricks by the Bay conventions',
'BBTB conventions',
'manage_options',
'bbtb_conventions',
'all_bbtb_conventions',
'dashicons-media-spreadsheet',
11
);
add_submenu_page(
'bbtb_conventions',
'Settings',
'Settings',
'manage_options',
'bbtb_settings',
function () { // anonymous callback function
include "includes/setting_page.php";
}
);
function all_bbtb_conventions() {
include "includes/add_convention.php";
}
}
}
So I checked if the function of the submenu works by replacing in the add_menu_page the 'all_bbtb_convention' with 'bbtb_settings'. Then the function works.
So there must be something in the add_submenu_page settings I am missing