Remove Query Strings from Static Sources in WordPress

This function will remove the “?ver” from the URLs of of your static resources on your WordPress site. For example, it will remove the “version” from the link to your .css and .js files. This can increase your page speed in tests by GTMetrix and Pingdom.

However, please note that some WordPress plugins depend on the “version” query strings and thus will break if you remove them. So, test to make sure that all of your plugins work after using this. (All of the 30+ plugins that I use work fine with this.)

// Remove the 'ver' query string from static files
function isa_remove_cssjs_ver( $src ) {
	// Does this URL have a query string beginning with ?ver=
	$ver = strpos( $src, '?ver=' );
	if ( $ver !== false ) {
		$parts = explode( '?', $src );
		$src = $parts[0];
	return $src;
add_filter('style_loader_src', 'isa_remove_cssjs_ver', 10, 2);
add_filter('script_loader_src', 'isa_remove_cssjs_ver', 10, 2);

Also see these for how to remove other query strings in WordPress:

Remove URL Query String Parameters from Gravatars in WordPress
Remove Query String From SyntaxHighlighter CSS URLs.

See more: ,


We've One Response

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: