Remove Versioning in Wordpress CSS and JS Scripts

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 http://yoursite.com/style.css?ver=1.0 into this http://yoursite.com/style.css

function remove_cssjs_ver( $src ) {
	if( strpos( $src, '?ver=' ) )
	src = remove_query_arg( 'ver', $src );
	return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
Remove Versioning from CSS and JS scripts

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 →