WordPress Hooks and Filters

Admin Hooks: admin_init, admin_menu and admin_enqueue_scripts

Use the main WordPress admin hooks correctly: admin_menu for pages, admin_init for settings and actions, current_screen for screen-specific logic, admin_enqueue_scripts with the hook suffix, admin_notices, and why admin_init also runs on AJAX requests.

WordPress admin request flow showing admin_menu, admin_init, current_screen and admin_enqueue_scripts

In the WordPress admin, admin_menu is where you add menu pages, admin_init is where you register settings and handle early admin actions, current_screen tells you which screen is loading, and admin_enqueue_scripts loads CSS and JavaScript, receiving the page's hook suffix so you can load assets only on your own screens. Note that admin_init also runs on admin-ajax.php and admin-post.php requests, so keep it light and do not redirect there without checks.

The order on an admin page

  1. init, as on every request.
  2. admin_menu builds the menu (network_admin_menu on multisite network screens).
  3. admin_init.
  4. current_screen, with a WP_Screen object.
  5. admin_enqueue_scripts, then admin_head.
  6. admin_notices, then the page content.
  7. admin_footer.

Our hook order guide covers the front-end sequence.

admin_menu: add pages

add_action( 'admin_menu', function () {
    $hook = add_menu_page(
        __( 'Events', 'acme' ), __( 'Events', 'acme' ), 'manage_acme_events',
        'acme-events', 'acme_render_dashboard', 'dashicons-calendar-alt', 25
    );
    add_submenu_page( 'acme-events', __( 'Reports', 'acme' ), __( 'Reports', 'acme' ),
        'manage_acme_events', 'acme-reports', 'acme_render_reports' );

    add_action( "load-{$hook}", 'acme_dashboard_load' );   // runs only for this page
} );

The load-{hook} action is perfect for page-specific work like processing actions or adding help tabs. See custom admin pages.

admin_init: settings and early handling

add_action( 'admin_init', function () {
    register_setting( 'acme_events', 'acme_events_settings', array( 'sanitize_callback' => 'acme_sanitize' ) );

    // Restrict wp-admin for subscribers, but not AJAX
    if ( wp_doing_ajax() ) {
        return;
    }
    if ( ! current_user_can( 'edit_posts' ) ) {
        wp_safe_redirect( home_url( '/account/' ) );
        exit;
    }
} );

Without the wp_doing_ajax() check, front-end AJAX features for subscribers would be redirected and break.

current_screen: screen-specific logic

add_action( 'current_screen', function ( WP_Screen $screen ) {
    if ( 'edit-event' === $screen->id ) {
        add_filter( 'months_dropdown_results', '__return_empty_array' );   // hide month filter
    }
} );

Screen IDs look like edit-post (list), post (editor), toplevel_page_acme-events or events_page_acme-reports.

admin_enqueue_scripts: load assets only where needed

add_action( 'admin_enqueue_scripts', function ( $hook_suffix ) {
    if ( ! in_array( $hook_suffix, array( 'toplevel_page_acme-events', 'events_page_acme-reports' ), true ) ) {
        return;
    }
    wp_enqueue_style( 'acme-admin', plugins_url( 'assets/admin.css', __FILE__ ), array(), '1.2.0' );
    wp_enqueue_script( 'acme-admin', plugins_url( 'build/admin.js', __FILE__ ), array( 'wp-element', 'wp-api-fetch' ), '1.2.0', true );
} );

Loading admin assets on every screen slows the dashboard and causes conflicts with other plugins. For block editor assets, use enqueue_block_editor_assets instead.

Other useful admin hooks

  • admin_notices: messages. See admin notices.
  • manage_{post_type}_posts_columns: list table columns. See admin columns.
  • admin_bar_menu: toolbar items (front end and admin).
  • admin_post_{action}: form handlers.
  • plugin_action_links_{plugin_file}: a "Settings" link on the Plugins screen.

Common mistakes

  • Adding menus on admin_init: too late; the menu is already built.
  • Redirecting on admin_init without checking AJAX.
  • Global admin assets.
  • Capability checks only in the menu: also check in the render and action handlers.
  • Heavy queries on admin_init: it runs on every admin request, including heartbeat AJAX calls.

Frequently asked questions

How do I find my page's hook suffix?

It is returned by add_menu_page() and add_submenu_page(). You can also log $hook_suffix in admin_enqueue_scripts.

Is admin_init the same as is_admin()?

is_admin() is true on admin screens and on admin-ajax requests; admin_init runs in both too.

Which hook for adding help tabs?

load-{hook} or current_screen, using $screen->add_help_tab().

Conclusion

Add pages on admin_menu, register settings on admin_init, branch on current_screen, and enqueue only for your hook suffixes. See the admin_init reference and the admin_enqueue_scripts reference. Related: login and registration hooks, mail hooks, hooks explained and plugin development. For LMS admin work, see our hooks overview, action hooks and filter hooks.

Need a cleaner admin for your team? See our customization service.

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.