How to Remove Query Strings From Static Resources in WordPress

/ Category: Tutorials / Comments: None

How to Remove Query Strings From Static Resources in WordPress
Spread the love

When testing a website to check it’s speed score and load time using the popular tools such as Gtmetrix, Pingdom and Google Page Speed, sometime we will get a low score in “Remove Query Strings from Static Resources”. URLs which contain special characters such as question marks (? ) and ampersand (&) are treated as Query Strings. Some proxy caching servers cannot cache the resources with special character in the URL, like : http://yoursite.com/wp-content/themes/yourtheme/css/style.css?ver=1.1.1.

According to GTmetrix, query strings or “resources with a ‘?’ in the URL are not cached by some proxy caching servers.” If you click on “What does this mean”:

“Most proxies, most notably Squid up through version 3.0, do not cache resources with a “?” in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.”

What is query string parameter?

It is a parameter that is used to pass information to the web server. The web server will use this information to serve the content to the visitor. For example, style.css?ver=1.1.1 could be used to ask the web server to serve the style.css file version 1.1.1, not the other versions. Query strings means that the content is dynamic, so web browsers don’t cache the resources with such parameters in the URL.

Why do web developers add query strings to static resources?

Web developers usually use query strings to prevent web browser from caching the resources. For example, if you use a theme on your website that load a style.css file, when a visitor enter the site then his web browser will load and cache that file. If the theme is updated and the style.css file changes, the same visitor who re-visit the site would still see the outdated style.css file from his web browser cache.

WordPress uses a query strings in many of its own static resources. This improves the user’s experience, but  also impacts the site performance in terms of loading time. In this guide, we will show you how to score high against “Remove Query Strings From Static Resources” in your WordPress site.

How to Remove Query Strings From Static Resources in WordPress

There are three options to remove the query strings from static resources:

1. Edit the theme’s function.php file

Go to your website dashboard – Appearance – Editor – Select Theme Functions (functions.php). It’s always a good idea to take backup of your functions.php before doing modifications. You can then paste the following code anywhere in your functions.php, but please add it after <?php in the first line, to make it easier to remember the modification you made.

function _remove_script_version( $src ){ 
$parts = explode( '?', $src ); 	
return $parts[0]; 
} 
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); 
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Once edited, click on “Update File” button to save the changes. Then, go to your favorite speed test tools like GTMetrix, Pingdom, Google PageSpeed, WebPageTest, etc. If you use a caching plugin, W3 Total Cache for example, do not forget to purge all cache before testing your site.

Now, your score will increase because the query strings from your domain name are now removed.

2. Use a plugin

There are several free plugins available that can help you to remove the query strings without having to edit you theme’s function.php file. In this example, we will use W3 Total Cache. To remove query strings by using W3 Total Cache, go to WordPress Dashboard – Performance – Browser Cache, then tick “Remove query strings from static resources”. Don’t forget to save and purge all cache before doing the speed test on GTMetrix or similar tools.

3. Remove them using CloudFlare.

Go login to your CloudFlare account then select the domain you use to host your WordPress site. Once selected, click on “Caching” box menu and then select caching level “No Query String”.

That’s it, from search engine’s point of view, a fast loading website is important. Nobody like to have another visit to a slow loading website. Make sure you look at all the aspects which are responsible for slowing down your site and rectify, including this query string issue.

When testing the loading time of our site, sometime it raises “Remove query strings from static resources” issue, this can be resolved and once it is resolved it will definitely bring in a positive effect to your website.


If you use one of our Managed Cloud VPS Hosting, you can simply ask our expert Linux admins to remove query strings from static resources in WordPress for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on Remove Query Strings From Static Resources in WordPress, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.

Be the first to write a comment.

Your feedback