0

I've tried to make the CSS changes “go live” on my site but nothing happened. Can you please help me? Usually when I update my CSS I need to force refresh all my browsers Chrome, Mozilla, and Opera (with F5) in order the changes in the CSS to take effect. So my problem is that I need to make the CSS to refresh automatically after a change is made.

This is the website: http://realvsbarcelona.com/ Thank you.

1
  • Do you enable any caching mechanism?
    – bravokeyl
    Commented Oct 6, 2016 at 16:23

2 Answers 2

1

If you add a version number in the wp_enqueue_script() call - fourth argument - it will append a query string to the css file reference and most (if not all) browsers will see that as a cache-breaker and force the asset to be requested again from the server.

https://developer.wordpress.org/reference/functions/wp_enqueue_script/

If you are hard-coding the script reference in your HTML then simply add a query string to the end: /mypath/some-stye.css?v=1234

Any changes to that v=1234 part will force the cached copy to be invalidated.

2
  • I've tried this, but no result: wp_enqueue_style( 'llorix-one-lite-style', get_stylesheet_uri(), array('llorix-one-lite-bootstrap-style'), rand(111,9999), 'all' ); Commented Oct 6, 2016 at 17:29
  • Be sure to read the documentation for the wp_enqueue_script function, which I linked within my answer. You are passing in a random number (which is a bad idea since it will reload the css EVERY time) -- and you are passing a number not a string. I'd try passing in a string as the $version value...
    – C C
    Commented Oct 6, 2016 at 17:41
0

I'm using this, coded into my header.php...

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="all" />

I think the idea is that it checks/appends the time of most recent modification, and thus serves what's current.

I'm not an expert, and will have grabbed this idea from somewhere.

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.