WordPress How To Remove Query Strings

Must Read

Are Lithium-Ion Batteries Recyclable?

Electric vehicles are growing every day, and they are certainly going to be the future of automotive...

NASA demonstrates its first all-electric aircraft

NASA has demonstrated it's first all-electric experimental which they have dubbed as the X-57 Maxwell. Its first...

Tesla to launch version three of solar roof tiles on October 25, 2019

Tesla is going to launch a new version of its solar roof tiles line up tomorrow October...
Scott Hartleyhttps://www.sertmedia.com
My name is Scott Hartley I am from Nashville, TN, and love to cover topics related to the latest tech trends, social media, and cars!

Query Strings are little lines of code that follow primarily your CSS and JS resources they look like this ?ver=1.1 (the only important part is the “?”. They are meant to show the version of the file so that in the event of it being updated the visitors to a website are served the latest version. The fundamental issue with Query Strings is they aren’t always cacheable to some proxies, and that there are some cases when they simply aren’t needed.

So how do you remove Query Strings? It’s quite simple really and it can be done in a few lines. To do this simply add the following lines to a child theme functions.php file or a site specific plugin.

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 );

By adding those lines it should remove the Query strings that append your CSS and JS. However, if you are using a plugin such as W3TC you have an extra step.

Solution For W3TC Users

If you are a fan of W3TC like I am you might have accidentally enabled Query Strings from the plugin. To remove them you need to go into your Browser Cache settings and uncheck “Prevent caching of objects after settings change” and save your settings.

Remove Query Strings W3TC

Solution For The Non-Technical 

If you are not a developer and are worried about adding code to your theme or creating your own plugin then the third and final option is to install a plugin. Now before, you say won’t that slow my site down the answer is no.

Adding a plugin to your site doesn’t make it slow but you should always try to do as much as you can with as few as possible. Adding one plugin that does the code above VS adding it to your functions.php file or in another plugin won’t make any difference in terms of performance.

Add the following plugin to your website and it contains the code I added above.

Remove Query Strings Plugin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest News

Are Lithium-Ion Batteries Recyclable?

Electric vehicles are growing every day, and they are certainly going to be the future of automotive...

NASA demonstrates its first all-electric aircraft

NASA has demonstrated it's first all-electric experimental which they have dubbed as the X-57 Maxwell. Its first test flight is going to...

Tesla to launch version three of solar roof tiles on October 25, 2019

Tesla is going to launch a new version of its solar roof tiles line up tomorrow October 25, 2019.

Huawei VR Glass Will Launch This December In China

Huawei will finally be launching its own virtuality reality headset. The device has been dubbed the Huawei VR Glass. This has been...

Google’s Defense For Wi-Fi 5 In Nest Wifi

Google has launched their new Nest Wifi system which is one part home network router and one part smart speaker. However, Google...

More Articles Like This