0

Im trying to modify WP admin area. I put this in the functions.php but the styling only takes effect the first time it runs the stylesheet, if I do any changes afterwards it doesnt update. For now it only works if I rename the stylesheet.

 function custom_admin() {
$url = get_settings('siteurl');
$url = $url . '/wp-content/themes/astra-child/wp-admin.css';
echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; } 
add_action('admin_head', 'custom_admin');
1

A more standard way to enqueue stylesheets in WP admin is to use wp_enqueue_style function on admin_enqueue_scripts hook.

if I do any changes afterwards it doesnt update

This sounds like a browser cache isssue. You can bust the cache by adding a dynamic version number parameter to the stylesheet url with the native php function filemtime. It returns the unix time when the file was last changed. Like so,

// add to functions.php
function my_prefix_add_admin_styles() {
  wp_enqueue_style( 'my_admin_styles', get_stylesheet_directory_uri() . '/wp-admin.css', false, filemtime( get_stylesheet_directory() . '/wp-admin.css' ) );
}
add_action( 'admin_enqueue_scripts', 'my_prefix_add_admin_styles' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.