Action Hook since 2.8.0
admin_enqueue_scripts
The correct hook to enqueue admin-only assets
Description
admin_enqueue_scripts is the admin equivalent of wp_enqueue_scripts — always check $hook_suffix so you don't load your CSS/JS on every admin screen.
When it runs
On every wp-admin page load, before the admin page markup renders.
Signature
do_action( 'admin_enqueue_scripts', string $hook_suffix );Parameters
$hook_suffixstring — The current admin page identifier, e.g. post.php or a plugin's own page hook.
Examples
Basic
add_action( 'admin_enqueue_scripts', function( $hook_suffix ) {
if ( 'post.php' !== $hook_suffix ) {
return;
}
wp_enqueue_script( 'my-admin-js', plugins_url( 'admin.js', __FILE__ ), [ 'jquery' ], '1.0', true );
} );Load a script only on the post edit screen.
Common Use Cases
- Enqueue admin CSS/JS scoped to one screen
- Load a color picker or media uploader script
- Pass data to admin JS via wp_localize_script
Common mistakes
- Enqueueing admin assets without checking $hook_suffix — they load on every admin page and slow the dashboard down
Related hooks
FAQ
How do I find the right $hook_suffix value?
Add error_log($hook_suffix) inside the callback and check your PHP error log while on the target screen, or use get_current_screen()->id.
Source: wp-admin/admin-header.php