Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

admin_enqueue_scripts

Loads stylesheets and scripts in the WordPress admin. Its $hook_suffix parameter tells you which admin screen is loading.

  • Type Action
  • From WordPress
  • Since 2.8.0
  • Fired in wp-admin/admin-header.php

When it fires

admin_enqueue_scripts runs on every admin page while the admin header is being built, before the styles and scripts in the are printed. The current user and screen are already set up.

Use $hook_suffix to load files only where they're needed. It's 'index.php' on the Dashboard, 'edit.php' on post lists, 'post.php' and 'post-new.php' in the editor, and values like 'toplevel_page_my-page' or 'settings_page_my-page' for pages added with add_menu_page() or add_options_page().

Parameters

Parameters
$hook_suffixstring The current admin page.

Example: Add CSS to the posts list only

PHP
add_action( 'admin_enqueue_scripts', function ( $hook_suffix ) {
	if ( 'edit.php' !== $hook_suffix ) {
		return;
	}
	wp_register_style( 'my-posts-list', false, array(), '1.0.0' );
	wp_enqueue_style( 'my-posts-list' );
	wp_add_inline_style( 'my-posts-list', '.fixed .column-title { width: 40%; }' );
} );

Good to know

  • Not sure of the value on a screen? Temporarily log it with error_log( $hook_suffix ) and reload the page.
  • The block editor's content area is usually an iframe, so admin CSS may not reach it. Use enqueue_block_assets for styles that affect post content.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.