WordPress Plugin page without showing in admin menu

To exclude a Plugin Option Page link from the WordPress Admin menu, simply register the menu leaving the parent menu slug empty.

function w4dev_register_admin_page_menu() {
    $mypage = add_submenu_page(
        '',
        'My Plugin Page',
        'My Plugin Page',
        'manage_options',
        'MyPlugInPage',
        'w4dev_admin_page_content'
    );
    add_action('load-'. $mypage, 'w4dev_load_admin_page_menu' );
}
add_action( 'admin_menu', 'w4dev_register_admin_page_menu' );

function w4dev_load_admin_page_menu(){}
function w4dev_admin_page_content(){}

This will create your plugin page without showing it in the admin menu. The page will be reachable at wp-admin/admin.php?page=MyPlugInPage. You can still use the w4dev_load_admin_page_menu function to handle requests/actions, and w4dev_admin_page_content to generate the template for your plugin.

Note: use an empty string '' for the parent slug, not null. Passing null there triggers deprecation notices on PHP 8.1+.

Leave a Reply

Your email address will not be published. Required fields are marked *