How to Remove Version from CSS and JS in WordPress?

How to Remove Version from CSS and JS in WordPress
1367 Views

In this blog, I’ll teach you how to remove the version from CSS and JS files in WordPress. Almost all CSS and js files in WordPress have the WordPress version number attached to the file names or included in the query string. Because the file is viewed as dynamic, having a query string in the URL does not cache it.

Remove version from js and css

Let’s start by removing versions from styles and scripts. To do so, add the code below to your active theme’s functions.php file. After adding the script to the functions.php file, you can view the source of any page’s version that should be removed from all your styles and scripts.

<?php
// Remove version from scripts and styles
function cxc_remove_css_js_version_callback( $src ) {
	if( $src && strpos( $src, '?ver=' ) ){
		$src = remove_query_arg( 'ver', $src );
	}
	return $src;
}

add_filter( 'style_loader_src', 'cxc_remove_css_js_version_callback', 9999 );
add_filter( 'script_loader_src', 'cxc_remove_css_js_version_callback', 9999 );

// Remove version from head
remove_action('wp_head', 'wp_generator');

// Remove version from rss
add_filter('the_generator', '__return_empty_string');
?>

Why is it necessary to remove the version number from CSS and JS files?

To enhance website performance as much as possible, query strings in CSS and JS files must be removed.

When we use a page speed analyzer, such as Google’s Page Speed, YSlow, or Pingdom, we are quite likely to find recommendations to delete query strings from CSS and JS files.

This is an issue since many proxies will not cache the resources if the URL contains a query string.

The upper code removes the version number from the header of your website.

What is the version number?

The version number is a piece of information that WordPress adds to your website. It tells people what version of WordPress you are using. If you have an old or insecure version, hackers can use this information to attack your site. You should always update to the latest and most secure versions of software as soon as possible.

Was this article helpful?
YesNo

1 comment

  1. Since the admin of this website is working, no question that very soon it will be well-known, due to its feature contents.

Leave a comment

Your email address will not be published. Required fields are marked *