How to apply a CSS file to my admin pages?

I have created a simple CSS file and I would like to apply it to one of my admin pages–specifically the ‘edit post’ page. I have tried two methods (described below), but both are failing–the CSS file in-question doesn’t seem to load at all. My CSS file is located in my parent theme directory, named admin-style.css, and consists of:

.ea-hide-admin {
visibility: hidden;
}

Attempt 1: From the WordPress Codex page on enqueuing admin scripts. To my functions.php I added:

function load_custom_wp_admin_style() {
wp_register_style( ‘custom_wp_admin_css’, get_template_directory_uri() . ‘/admin-style.css’);
wp_enqueue_style( ‘custom_wp_admin_css’ );
}
add_action( ‘admin_enqueue_scripts’, ‘load_custom_wp_admin_style’ );

This failed, and the error log indicated wp_enqueue_style() evaluated to false. I also tried the admin_head hook here instead, but that failed with the same error.

Attempt 2: From this previous Stack Exchange question. To my functions.php I added:

function wpse239532_load_admin_style() {
wp_enqueue_style( ‘admin_css’, get_stylesheet_directory_uri() . ‘/admin-style.css’, false, ‘1.0.0’ );
}
add_action( ‘admin_enqueue_scripts’, ‘wpse239532_load_admin_style’ );

This also failed, and the error log indicated that wp_enqueue_style() is evaluating to false.

I have confirmed the CSS file in-question exists in the proper directory (screenshot).

Read more here:: How to apply a CSS file to my admin pages?

Leave a Reply

Your email address will not be published. Required fields are marked *