WordPress Development

How to Add a Custom Admin Page in WordPress

Add top-level and submenu admin pages with add_menu_page and add_submenu_page: capabilities, rendering, handling form submissions safely, loading assets only on your page, and admin UI conventions.

WordPress admin sidebar with a custom Reports menu and its submenu pages

To add a custom admin page, hook a function to admin_menu and call add_menu_page() for a top-level item or add_submenu_page() to place it under an existing menu, such as Tools or Settings. Each call takes a page title, menu title, required capability, a unique slug and a callback that prints the page. Handle form submissions with a nonce and capability check, and load CSS and JavaScript only on your page using the hook suffix the function returns.

Register the pages

add_action( 'admin_menu', function () {
    $hook = add_menu_page(
        __( 'Reports', 'tle' ),     // page title
        __( 'Reports', 'tle' ),     // menu title
        'manage_options',           // capability
        'tle-reports',              // slug
        'tle_render_reports',       // callback
        'dashicons-chart-bar',      // icon
        58                          // position
    );
    add_submenu_page(
        'tle-reports',
        __( 'Export', 'tle' ),
        __( 'Export', 'tle' ),
        'manage_options',
        'tle-reports-export',
        'tle_render_export'
    );
    add_action( "load-{$hook}", 'tle_reports_load' ); // runs before output on this page only
} );

Prefer a submenu under Tools (add_management_page()) or Settings (add_options_page()) for small features, so the sidebar stays tidy.

Render the page

function tle_render_reports() {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    ?>
    <div class="wrap">
        <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
        <?php settings_errors( 'tle_reports' ); ?>
        <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
            <input type="hidden" name="action" value="tle_rebuild_report">
            <?php wp_nonce_field( 'tle_rebuild_report' ); ?>
            <?php submit_button( __( 'Rebuild report', 'tle' ) ); ?>
        </form>
    </div>
    <?php
}

The wrap class, submit_button() and standard admin markup make your page match the rest of WordPress.

Handle the form safely

add_action( 'admin_post_tle_rebuild_report', function () {
    check_admin_referer( 'tle_rebuild_report' );
    if ( ! current_user_can( 'manage_options' ) ) {
        wp_die( esc_html__( 'Not allowed.', 'tle' ), 403 );
    }
    tle_rebuild_report();
    wp_safe_redirect( add_query_arg( 'updated', '1', admin_url( 'admin.php?page=tle-reports' ) ) );
    exit;
} );

Posting to admin-post.php and redirecting afterwards avoids duplicate submissions on refresh. Nonces are explained in WordPress nonces. For plain settings, the Settings API does this for you (plugin settings pages).

Load assets only on your page

add_action( 'admin_enqueue_scripts', function ( $hook_suffix ) {
    if ( 'toplevel_page_tle-reports' !== $hook_suffix ) {
        return;
    }
    wp_enqueue_style( 'tle-reports', plugins_url( 'assets/reports.css', __FILE__ ), [], '1.0' );
} );

Build richer screens

  • Lists with sorting and bulk actions: extend WP_List_Table (an internal class, so keep your copy compatible).
  • Extra columns on existing lists: custom admin columns.
  • Quick stats on the dashboard: dashboard widgets.
  • React-based screens: render an empty container and mount a React app built with @wordpress/scripts and @wordpress/components.

Common mistakes

  • Using a role name like administrator instead of a capability.
  • Processing forms inside the render callback after headers are sent.
  • Loading scripts on every admin page.
  • A top-level menu for a single small setting.
  • Printing unescaped data in tables.

Frequently asked questions

Why do I get "Sorry, you are not allowed to access this page"?

The user lacks the capability, or the slug in the URL does not match a registered page (fixing that error).

How do I find my page's hook suffix?

Use the value returned by add_menu_page(), or log $hook_suffix in admin_enqueue_scripts.

Can editors see my page?

Use a capability they have, such as edit_others_posts, or a custom capability you grant to roles.

How do I add a notice after saving?

Use add_settings_error() with settings_errors(), or an admin notice (admin notices).

Conclusion

Register under the right menu with a real capability, render with admin markup, process forms through admin-post with nonces, and scope assets to your page. See the Administration Menus handbook and add_menu_page() reference, debug with the debugging guide, and continue the roadmap.

Need custom admin tools for your team? Talk to our developers.

Save this practical guide

Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.

· Tutor LMS developers

Guides written and reviewed by the TutorLMS Expert development team. Every hook, function, table and setting we mention is checked against the Tutor LMS and Tutor LMS Pro source code before it is published.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.