Using WordPress ‘admin_print_styles’ PHP action

The admin_print_styles WordPress PHP action fires when styles are printed for all admin pages.

Usage

add_action('admin_print_styles', 'your_custom_function');
function your_custom_function() {
// Your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: admin_print_styles

Examples

Enqueue a custom admin stylesheet

Enqueue a custom stylesheet for the WordPress admin area.

function enqueue_custom_admin_stylesheet() {
wp_enqueue_style('custom-admin-styles', get_template_directory_uri() . '/admin-styles.css');
}
add_action('admin_print_styles', 'enqueue_custom_admin_stylesheet');

Remove a specific stylesheet from the admin area

Remove a specific stylesheet from the WordPress admin area by its handle.

function remove_specific_admin_stylesheet() {
wp_dequeue_style('plugin-admin-styles');
}
add_action('admin_print_styles', 'remove_specific_admin_stylesheet');

Apply custom CSS styles directly to the admin area

Apply custom CSS styles directly to the WordPress admin area using a <style> tag.

function add_custom_admin_styles() {
echo '<style>
body {
background-color: #f5f5f5;
}
</style>';
}
add_action('admin_print_styles', 'add_custom_admin_styles');

Load Google Fonts in the admin area

Load Google Fonts in the WordPress admin area.

function enqueue_google_fonts_admin() {
wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css?family=Roboto&display=swap', false);
}
add_action('admin_print_styles', 'enqueue_google_fonts_admin');

Conditionally load a stylesheet in the admin area

Load a custom stylesheet in the WordPress admin area for a specific post type only.

function enqueue_custom_post_type_stylesheet() {
    $screen = get_current_screen();
    if ($screen->post_type == 'your_custom_post_type') {
        wp_enqueue_style('custom-post-type-styles', get_template_directory_uri() . '/custom-post-type-styles.css');
    }
}
add_action('admin_print_styles', 'enqueue_custom_post_type_stylesheet');