Admin pages are often used for plugin or theme settings, and sometimes for user guide. However, there are situations you want to add a hidden admin page that only shows under a specific condition, and won't show in the admin menu. Pages such as WordPress welcome page, credit page for new versions are examples. These page are displayed only once when users update their WordPress websites and they contain only information about the new versions. Plugin authors might want to add similar pages that shows a quick start guide for users when they first install their plugins. And this tutorial will show you how to do that.

Meta Box includes a hidden "About" page to show the getting started guideline to users. See the screenshot below:
The "About" page of Meta Box plugin

Creating an admin page

The first step is creating an admin page. We can do that via add_menu_page or add_submenu_page. We also can use shortcut of them like add_dashboard_page or add_options_page. You can see the full list of these actions on the Codex.

Because the admin page we're going to create is hidden, it doesn't matter where it's inserted. So let's just use the add_dashboard_page to add it under the Dashboard menu:

add_action( 'admin_menu', function() {
    add_dashboard_page(
        __( 'Welcome', 'textdomain' ),
        __( 'Welcome', 'textdomain' ),
        'manage_options',
        'my-welcome',
        'prefix_render'
    );
} );

Render the page content

The last parameter in the function add_dashboard_page above is a callback function that renders the page content. You can output a welcome message the way you want:

function prefix_render() {
    echo '<div class="wrap">';
    // Your content
    echo '</div>';
}

Hide the admin page

The last step is the most important one: hide the admin page. To do this, we use a simple trick: remove the admin menu on admin_head hook. The code is as simple as follows:

add_action( 'admin_head', function() {
    remove_submenu_page( 'index.php', 'my-welcome' );
} );

Now your admin page is hidden from the main admin menu. To access to that page, you have to type the URL in the address bar: domain.com/wp-admin/?page=my-welcome. You can put the link somewhere in your plugin to provide extra information to users if they want to see.

Alternatively, you can register and hide the admin page at the same time by setting the parent_slug parameter to null in the function add_submenu_page, like this:

add_action( 'admin_menu', function() {
    add_submenu_page(
        null,
        __( 'Welcome', 'textdomain' ),
        __( 'Welcome', 'textdomain' ),
        'manage_options',
        'my-welcome',
        'prefix_render'
    );
} );

Both methods work quite well. However, the first method (add and remove) can highlight the parent menu when visiting this hidden admin page, while this method cannot.

Using this technique, you can create a welcome page for your plugin that helps users understand what the plugin is, what is it for and how to get started. You can also use it to create a special pages such as support, subscription, etc. while not messing up the admin menu.

3 thoughts on “How to Create a Hidden Admin Page in WordPress

  1. Here :

    add_action( 'admin_head', function() {
    remove_submenu_page( 'index.php', 'my-welcome' );
    }

    it's missing );

    so it should be

    add_action( 'admin_head', function() {
    remove_submenu_page( 'index.php', 'my-welcome' );
    });

  2. just figured out the "hide" part isn't even necessary, if you set the 3rd parameter on add_submenu_page to '' then it won't display in the menu

Leave a Reply to iPinky77 Cancel reply

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