Remove Query Strings from WordPress Resources

If you’ve analyzed your WordPress blog with services like GTmetrix or Pingdom Tools, you may have been advised to remove query strings from static resources. That is to remove the part of your resource string (URL) that indicates your WP / Theme / Plugin version number.

Their reasoning is that some Proxy Caching servers do not cache resources with a URL that contains query strings aka version numbers. If you are using Cloudflare then you do not need to do this since Cloudflare has an option that can be set to cache those files.

But if you still want to remove the version numbers to have a higher performance score on sites like Pingdom Tools and GTmetrix then follow the instructions below.

Remove Version Number from Styles and Scripts

From this:

To this:

Add this little code snippet to your child-theme’s functions.php

add_filter( 'script_loader_src', 'remove_resource_version', 20 ); 
add_filter( 'style_loader_src', 'remove_resource_version', 20 );

function remove_resource_version( $src ) {

	if ( is_admin() )
		return $src;

	$output = explode( '?ver=', $src );
	return $output[0];

Using (?ver=) instead of simply (?) to filter the query strings ensures that other resources like Google Fonts — which usually uses something like — don’t get cut off.

Share This Post

1 Comment

Add a Comment
  1. Nice. Please share more light on how to add the above code, am not good in coding but i found this article helpful and I need to implement it..


Leave a Reply

Please write your comments in english. I delete anything that even remotely resembles spam.

Note: When posting code, enclose it in pre and code tags.
e.g. Add code here