How to Remove Query Strings From Static Resources

What are query strings?

Query strings are the URLs that contains a special character (like “?”, “&”). You may have seen these in Website Speed Test Tools such as Pingdom, Gtmetrix, and Google’s PageSpeed Insights, They suggest to Remove Query Strings From Static Resources. But How? If You are here to wondering this Question then You are at the Right Place.

Example- 017/03/Blogger-Vs-WordPress.png?resize=300%2C150

How to Remove Query Strings From Static Resources

There are many ways to remove query strings. Here I’ve shared some of them-

  • By Editing your function.php file

    You can Remove the Query Strings by adding this small code on your function.php file. This is the most effective way of removing Query Strings.

Add this Code to the bottom of your function.php file which can be found in Appearence>Editor in Your WordPress Dashboard

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

Remove Query Strings By using Plugins-

In my Vision, the best part of WordPress is that for doing almost anything You Have Plugins. You Don’t have to Do manually. And for this Purpose also You Have Some Plugins. You Can search for a plugin or use this Plugin- Remove Query Strings From Static Resources

There is more new Plugin that removes query strings from static resources. Also, check those out.

Bonus For W3 Total Cache Plugin Users

If You use W3 Total Cache Plugin, then there is an option called “Prevent Caching of objects of objects after settings change”. This can be found in the W3 plugin Performance Tab> Browser Cache.  This may be unchecked to avoid creation of Query Strings but if it is enabled, just deselect it and Save Settings to Prevent the creation of query strings.

These are some of the Ways to Remove Query Strings, However, There are more.

If You have some more suggestion /Questions, The Comment Box is For you. Feel Free to Comment.

2 thoughts on “How to Remove Query Strings From Static Resources”

Leave a Reply

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