最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

menus - WP admin style not refreshing

programmeradmin4浏览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');

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
Add a comment  | 

1 Answer 1

Reset to default 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' );
发布评论

评论列表(0)

  1. 暂无评论