Core Admin Hooks
admin_init
- Early hook for registering settings, capabilities, etc.
- “The admin’s
init hook”
admin_menu
- Add top-level/submenu pages
- Pro Tip: Use
add_menu_page() here
admin_head-{hook_suffix}
- Inject CSS/JS into specific admin pages
- Example:
admin_head-toplevel_page_my-plugin
🖥️ Page-Specific Hooks
load-{hook_suffix}
- Pre-render setup for specific pages
- Example:
load-edit.php (Posts list screen)
admin_notices
- Display admin notices/errors globally
- Bonus: Use
get_current_screen() to target specific screens
in_admin_header
- Insert content at the top of admin pages (before notices)
📝 Post/Editor Hooks
save_post
- Trigger actions when posts are saved
- Advanced: Use
$post->post_status checks
add_meta_boxes
- Register custom meta boxes for post types
admin_enqueue_scripts
- Enqueue scripts/styles ONLY in admin
- Critical: Always check
$hook_suffix
🗃️ List Table Hooks
manage_{post_type}_posts_columns
- Modify columns in post list tables
- Example:
manage_product_posts_columns
manage_{post_type}_posts_custom_column
- Render custom column content
- Paired with the above hook
bulk_actions-{screen}
- Add/remove bulk actions
- Example:
bulk_actions-edit-post
⚙️ User & Dashboard Hooks
show_user_profile / edit_user_profile**
- Add fields to user profiles
wp_dashboard_setup
- Modify the WordPress dashboard
- Example: Remove default widgets
admin_bar_menu
- Modify the admin toolbar
- Pro Tip: Check
is_admin() for context
🛠️ Advanced Power Hooks
plugin_action_links_{plugin}
- Add links to plugins list (e.g., “Settings”)
- Example:
plugin_action_links_my-plugin/my-plugin.php
admin_post_{action}
- Handle custom admin form submissions
- Security: Always include nonce checks
upgrader_process_complete
- Run code after updates (plugins/themes/core)
wp_ajax_{action} / wp_ajax_nopriv_{action}**
- Handle AJAX requests (admin/front-end respectively)
admin_xml_ns
- Add XML namespaces to admin head (rare but useful for integrations)
🎯 When to Use Which Hook?
| Scenario | Recommended Hook |
|---|
| Adding a settings page | admin_menu |
| Saving post meta | save_post |
| Modifying post columns | manage_{type}_posts_columns |
| Adding help tabs | load-{page} |
| Admin notices | admin_notices |
| Custom admin AJAX | wp_ajax_{action} |
💡 Pro Tips
- Debug hooks with:phpadd_action(‘all’, function($hook) { if (strpos($hook, ‘admin’) !== false) { error_log(“Admin hook fired: {$hook}”); } });
- Always check capabilities:phpif (!current_user_can(‘manage_options’)) return;
- Prefix your hooks to avoid collisions:phpadd_action(‘admin_init’, ‘myplugin_admin_init’);
add_action('all', function($hook) {
if (strpos($hook, 'admin') !== false) {
error_log("Admin hook fired: {$hook}");
}
});
if (!current_user_can('manage_options')) return;
add_action('admin_init', 'myplugin_admin_init');