The admin_print_styles-{$hook_suffix} WordPress action fires when styles are printed for a specific admin page based on $hook_suffix
.
Usage
add_action('admin_print_styles-{hook_suffix}', 'your_custom_function'); function your_custom_function() { // your custom code here }
Parameters
None
More information
See WordPress Developer Resources: admin_print_styles-{$hook_suffix}
Examples
Enqueue a custom CSS file for the admin dashboard
This code enqueues a custom CSS file only for the admin dashboard.
add_action('admin_print_styles-index.php', 'enqueue_custom_dashboard_styles'); function enqueue_custom_dashboard_styles() { wp_enqueue_style('custom-dashboard-styles', get_template_directory_uri() . '/css/dashboard.css'); }
Enqueue a custom CSS file for the plugins page
This code enqueues a custom CSS file only for the plugins page.
add_action('admin_print_styles-plugins.php', 'enqueue_custom_plugin_styles'); function enqueue_custom_plugin_styles() { wp_enqueue_style('custom-plugin-styles', get_template_directory_uri() . '/css/plugins.css'); }
Enqueue a custom CSS file for the post editing screen
This code enqueues a custom CSS file only for the post editing screen.
add_action('admin_print_styles-post.php', 'enqueue_custom_post_styles'); function enqueue_custom_post_styles() { wp_enqueue_style('custom-post-styles', get_template_directory_uri() . '/css/post.css'); }
Enqueue a custom CSS file for the theme options page
This code enqueues a custom CSS file only for the theme options page.
add_action('admin_print_styles-appearance_page_theme_options', 'enqueue_custom_theme_options_styles'); function enqueue_custom_theme_options_styles() { wp_enqueue_style('custom-theme-options-styles', get_template_directory_uri() . '/css/theme-options.css'); }
Enqueue a custom CSS file for the custom post type editing screen
This code enqueues a custom CSS file only for the custom post type editing screen.
add_action('admin_print_styles-post-new.php', 'enqueue_custom_cpt_styles'); function enqueue_custom_cpt_styles() { global $typenow; if ('your_custom_post_type' === $typenow) { wp_enqueue_style('custom-cpt-styles', get_template_directory_uri() . '/css/custom-post-type.css'); } }