Remove Query Strings From Static Resources In WordPress
In this articles we are going to discuss how you can remove Remove Query Strings From Static Resources In WordPress and why it is important to remove this error . When we are talking about speed of website page load time the important for our website . we can test our page load time by using Pingdom and GTMetrix and google pagespeed insights and you might get this warning error .
When you will scan you website in gtmetrix or pingdom tool . you will get query like ?ver=2.6 at the end of your javascript files or css file These are called query strings . they represents version number of the files of plugin or themes when they updated last . For example https://www.gomahamaya.com/wp-includes/js/jquery.js?ver=1.12.4 . this is used for tracking the updated version of the plugin or theme .
It is important to remove it because the file with version number some times can’t be cached and can cause caching issue .
Function.php (Without Plugin Method)
You need to paste the following code in the function.php which is going to remove all query string from the css and javascript files without touching any file .
Hover over appearance << then click on editor << then paste the code in function.php
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 );
Note – You can’t Remove Query Strings From Static Resources via .htacess file
Type 2 (Plugin Method)
Best WordPress Plugin To Remove Query Strings From Static Resources In WordPress are as follows
1. Autoptimize Plugin Method
Autoptimize plugin is very famous plugin for optimization which have very vast spoke in optimization . They have provided the option to remove version number of the scripts .
Steps required
click on autoptimize setting >> click on extra setting >> check the option ” Removing query strings (or more specificaly the ver parameter) will not improve load time, but might improve performance scores ” then click on save change and flush the cache file.
2. W3 Total Cach Plugin Method
W3 total cache and wp super cache are most famous plugin used for caching and if you are already using w3 total cache then you just need to uncheck this function , no need to paste extra code via function.php . w3 cache total is also going to increase your website speed if you will configure it properly .
Steps required
Open w3 cache total setting >> then click on browser cache tool << inside browser caching uncheck “Prevent caching of object after setting change” and click on save change and empty the cache
3. Cloudflare Method
If you are using clouflare . then you need to first login into that then click on caching >> then inside caching level setting select no query string . Then click on purge all everything then click and click on save change
4. Wp rocket Method
Wp rocket is one of the most famous premium version plugin used for minification and caching . They too provide option to remove file version . with just one click
Steps Required
click on setting >> then check the option remove query string >> click on save change
5.query-strings-remover
There so many plugin in WordPress respiratory but this Query Strings Remover is lightweight and east to use just check that box to check that option and save the changes. And you are ready to rock
Note – You need to Purge the cache before you test again and choose only one method
Best option (no settings / database query):
https://wordpress.org/plugins/remove-query-strings-littlebizzy/
Hello Mateo ,
I really appricate your feedback and accept your words littlebizzy products are really good and worth . You can use it without any problem .
You can try wp-rocket from this page https://gomahamaya.com/best-cache-plugins-wordpress/ . That has all feature which is require to optimize any website .