4

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?

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.org/reference/functions/wp_enqueue_style
    – mmm
    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! Mar 5, 2021 at 3:22

3 Answers 3

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.

2
3

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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