WordPress How To Remove Query Strings

9
16

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 PluginOriginal Article

9 COMMENTS

  1. Hello,I log on to your blogs named “WordPress How To Remove Query Strings – TheCrazyReader” daily.Your story-telling style is witty, keep up the good work! And you can look our website about [url=http://www.wedding0venues.tk/]how to plan a small wedding[/url].

  2. Hi,I log on to your new stuff named “WordPress How To Remove Query Strings – TheCrazyReader” on a regular basis.Your story-telling style is awesome, keep doing what you’re doing! And you can look our website about تحميل اغانى.

  3. Heya i’m for the first time here. I came across this board and I find It really useful &
    it helped me out a lot. I hope to give something back and help others like you helped me.

  4. I just could not leave your site prior to suggesting that I really loved the standard
    info a person supply for your guests? Is gonna be again continuously to check up on new
    posts

LEAVE A REPLY