If I understand you, what you are doing is almost correct. You need add_menu_page
instead of add_submenu_page
add_action('admin_menu', 'register_my_custom_submenu_page');
function register_my_custom_submenu_page() {
add_menu_page( 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' );
}
function my_custom_submenu_page_callback() {
echo '<h3>My Custom Submenu Page</h3>';
}
As far as the “embedded” PHP, you already have it. Everything in that code is PHP. You can add whatever other PHP you want inside that callback (my_custom_submenu_page_callback
) and it should work so long as the PHP itself is valid and you watch out for variable scope and such.
Your capability– manage_options
— may need to be changed. That depends on how you want it to work.