How to Remove Query Strings From Static Resources in WordPress

Website speed is an extremely essential aspect for website or blog. It give best user experience to your visitors. It also affect a search engine ranking. You can also visit 10 simple tricks to Boost your Website Page Loading speed.  When you are testing your website on tools such as Gtmetrix , Pingdom , or Google’s PageSpeed Insights you have notify a suggestion to remove query strings from static resources. You may have  also question that what is query string? Query string is the URLs that containing special characters such as “&” and “?”. CSS file and JS file means Script and  stylesheets can sometimes contain a url with query string in  order to identify the version of the asset or for purposes of cache. Query string look like in css is:

<pre>

/wp-includes/css/lsmaincustom.min.css?ver=4.4.2

</pre>

It’s most important to remove query string because it affect the website speed. So Let’s have a look how to remove query strings from static resources in wordpress.

Here is 2 way to remove query strings from static resources in wordpress.

    1. 1. Remove query strings from static resources in wordpress using code
    2. 2. Remove query strings from static resources in wordpress using plugin

Remove query strings from static resources in wordpress using code

Add below line of  code at the end of your theme’s functions.php file of your active child theme (or theme) and Save the file.

<pre>

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

</pre>

you should no longer see a warning about query strings in website speed test tools.

Remove query strings from static resources in wordpress using plugin

You can download Query Strings Remover from wordpress repository or on your wordpress dashboard in plugin option click "Add New" plugin and searching for it. Installed it and active it. After installation clear all catch to see the changes. you didn’t see any warning about query string. You can also use Remove Query Strings From Static Resources plugin for remove query strings from static resources in wordpress. You don’t need to do anything with this plugin. Just installed and active as do the same thing as above plugin.

I hope this post is useful for your website. If you need any help than please contact our experience wordpress developer at Lathiya Solutions, Surat.