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

cache - Automatically Refresh WordPress Stylesheet

programmeradmin2浏览0评论

I am currently using a Mac computer and I cannot figure out how to refresh my website when I make changes to my WordPress stylesheet file. I have tried Cmd+R for hard reloading, I have tried emptying the caches, but nothing seems to work – the old version is still loaded nonetheless.

I have used a windows computer before and every time I made a style change with my style.css sheet, I would just press ctrl + F5 and it would hard refresh right away.

Does anyone know any tricks other than Cmd+R or clearing the caches to automatically refresh the stylesheet?

I am currently using a Mac computer and I cannot figure out how to refresh my website when I make changes to my WordPress stylesheet file. I have tried Cmd+R for hard reloading, I have tried emptying the caches, but nothing seems to work – the old version is still loaded nonetheless.

I have used a windows computer before and every time I made a style change with my style.css sheet, I would just press ctrl + F5 and it would hard refresh right away.

Does anyone know any tricks other than Cmd+R or clearing the caches to automatically refresh the stylesheet?

Share Improve this question edited Sep 23, 2019 at 14:30 Siavas 1054 bronze badges asked Oct 10, 2017 at 21:54 CakersCakers 1811 gold badge2 silver badges6 bronze badges 2
  • 2 you can set the version with wp_enqueue_stylethen every time you change something, change the version number and this will force the reload because URL ends with "...css?ver=12" developer.wordpress/reference/functions/wp_enqueue_style – mmm Commented Oct 10, 2017 at 21:58
  • #mmm I've had this problem for almost 20 days. I've been on support with the host 3 times. Your solution could have saved me hours of frustration, if I had found it first! – Nora McDougall-Collins Commented Mar 5, 2021 at 3:22
Add a comment  | 

3 Answers 3

Reset to default 4

"Quick" fix: Right Click -> view page source ( ctrl+U ), find .css file you changed, open it in new tab and reload ( you should see change in place you've made it )

ONLY in development mode add php function time() in place of version number

wp_enqueue_style( $handle, $src, array(), time() , 'all' );

Delete cache if you use caching plugin.

If you're using cache for your styles you need to refresh cache, turn off a cache plugin or just add "time()" function to your version of your styles.

wp_enqueue_style( 'some-style', get_stylesheet_directory_uri() . '/yourpath.css', array(), time());

More info you can find here about styles in wordpress. wp_enqueue_style

this can actually be a complex problem and may have many dimensions:

Please define further: Are you developping locally (server, DB is on your computer) or remotely (Hosting, FTP, etc.)

Caching can be really a bitch: The WebHosting may have a Cache mechanism working (e.g. Varnish Cache) The Wordpress may have a Caching mechanism (as e.g. W3CTotalCache) With the Browser Cache you have set a long Caching for css files (.htaccess)

So if you have a good htaccess setup etc. all three caches should make it harder to refresh (specially) css changes. As mmm pointed ot, to include the version in the functions.php is a very helpful and recommended method, but doesn't always work (for example Varnish Cache)

So if you're in development, it's recommendable to turn off al caches while you are doing css changes, and stay with the "version number refresh", it's the most recommended method. If it's already a production site, I recommend you to get used to empty all three caches before the refresh (for a few changes it's no problem).

But there's no easier way, that's what caches and long-lifes are for.

发布评论

评论列表(0)

  1. 暂无评论