Ecommerce Shopify WordPress Discussion

Updating CSS in WordPress

I am working in Wordpress and I have custom css files that are part of my theme. These files are working fine, but after a week I went back to edit the CSS in them and the updates aren't rendering to the page. In my inspector tool, I noticed the file is books.css/ver=6.3.2 and I feel like that is what I need to update. I tried clearing my cache, going incognito, etc and haven't found a solution. After Chat GPTing, I added a random version calculator at in the fuction.php file, so now the call looks like this: wp_enqueue_style( 'books', get_stylesheet_directory_uri() . '/books.css', array(), rand(111, 9999)); This works but I am curious why and how and if there is another solution that doesn't seem as odd.
If we take a closer look at the Wordpress docs of wp_enqueue_style (https://developer.wordpress.org/reference/functions/wp_enqueue_style/), the 4th argument is $ver. By default if you omit it, it will default to your WP version i.e 6.3.2. Many Wordpress and hosting caching solutions as well as local browser caches use the ver of CSS and JS files to determine whether the file should be requested again aka clear the cached version. If you don't want this file cached you can do any of the following: exclude the CSS file from your Wordpress caching plugin exclude the CSS file from your hosting caching solution However I would not recommend any of the above. The good practice is to update the ver everytime you change the file and it should be requested again: if ( ! defined( '_S_VERSION' ) ) { // Replace the version number of the theme on each release. define( '_S_VERSION', '1.0.0' ); } function my_scripts() { // CSS Files wp_enqueue_style( 'books', get_stylesheet_directory_uri() . '/books.css', array(), _S_VERSION ); } add_action( 'wp_enqueue_scripts', 'my_scripts', 200 );

December 30, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.