I would like to force a style.css reload for users, as their browser cache might mess up the design. I am trying to work with a version to it (f.e. style.css?ver=2
).
Is that the best way to do it? Eventually I might look into running this dynamic as shown on link. But right now I cannot even get this to work.
I am using Salient Theme, and they have an enqueue.php script which loads the .css files if I am correct. For now, I have added the ?ver=2
to the code below. However, this still now changes the output when I look at my homepage. I have cleared cached and double checked whether query-strings are allowed. But server caching and WP-rocket seem to allow this. Any pointers on how I can get this working to force the style.css reload?
if( is_child_theme() ) {
$nectar_theme_version = nectar_get_theme_version();
wp_register_style( 'salient-child-style', get_stylesheet_directory_uri() . '/style.css?ver=2', '', $nectar_theme_version );
wp_enqueue_style( 'salient-child-style' );
}
UDPATE:
I have tried changing that code to /style2.css
. That does seem to update the output. So seems I am in the right settings, but the query is being cut off.
3
Answers
Put these meta tags in your header.php file (inside head tag):
I would programmatically version it using
filemtime
. Even if the version is not showing, the browser should be reading the new file:Basically, this will get the file’s modified time and if it’s different, the version will update and let the browser know the version changed. Also you really don’t need a separate
wp_register_style
, but if you want to keep it:Best way is to give version to your styles after each update!