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');
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');
Share
Improve this question
asked Jun 8, 2019 at 7:49
bozenbozen
611 silver badge3 bronze badges
1 Answer
Reset to default 1A 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' );