Remove Versioning in WordPress CSS and JS Scripts

When you’re optimizing your website, you’ve probably noticed a page speed score telling you to remove versioning from your CSS and JavaScript files in WordPress.

Here’s a quick code snippet to remove version numbers so you can optimize your website.

Code Snippet

Place this code snippet in your functions.php file. It will remove all version numbers that are appended to the end of enqueued CSS and JavaScript files in your WordPress theme.

Simply, turn this into this

[pastacode lang=”css” manual=”function%20remove_cssjs_ver(%20%24src%20)%20%7B%0A%09if(%20strpos(%20%24src%2C%20’%3Fver%3D’%20)%20)%0A%09src%20%3D%20remove_query_arg(%20’ver’%2C%20%24src%20)%3B%0A%09return%20%24src%3B%0A%7D%0Aadd_filter(%20’style_loader_src’%2C%20’remove_cssjs_ver’%2C%2010%2C%202%20)%3B%0Aadd_filter(%20’script_loader_src’%2C%20’remove_cssjs_ver’%2C%2010%2C%202%20)%3B” message=”Remove Versioning from CSS and JS scripts” highlight=”” provider=”manual”/]

When to remove version numbers from WordPress files

During website optimization, determine if your CSS and JavaScript files will change often. If they’ll stay fairly static, you’re safe to remove the version number.

This helps with page speed scores from Pingdom, GT Analytics and Google Page Speed. And it really not needed until you make changes again.

Optimization is an important step after you’ve launched your new WordPress website. After development of all CSS and JS, there’s typically no need to include versioning of your CSS and JS files.

When to use version numbers

Use version numbers when you send updates to clients.

The last thing you want to do is send a client the updates they’ve asked for and for the client to view the old version of their website. They’ll call and say, “No. You haven’t made the changes. I still see the same thing. What’s wrong with you?”

At this point, you’ll have to use developer jargon: “The CSS is cached in your browser. Go back to the page and hard refresh and see if that works.” Whether it works or if the browser is keeping the cache for another 2 weeks, the client is now crossed eyed and annoyed.

Clients just want it done right the first time.

Save sanity by using version numbers during development and client updates.

Increase page speed by removing version numbers when you plan for the scripts to sit for awhile.


Take Control of the Beaver Builder Theme Footer with Shortcodes →

Leave a Comment