Remove Query Strings From Static Resources In WordPress
In this article, 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 the 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 page speed insights and you might get this warning error.
When you will scan your website in gtmetrix or Pingdom tool. you will get queries like ?ver=2.6 at the end of your javascript files or CSS file These are called query strings. they represent the version number of the files of plugins or themes when they were 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 sometimes can’t be cached and can cause a 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 strings 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 the .htacess file
Type 2 (Plugin Method)
Best WordPress Plugin To Remove Query Strings From Static Resources In WordPress is as follows:
1. Autoptimize Plugin Method
Autoptimize plugin is a very famous plugin for optimization which has very vast spoke in optimization. They have provided the option to remove the version number of the scripts.
Steps required
click on autoptimize setting >> click on extra setting >> check the option ” Removing query strings (or more specifically the ver parameter) will not improve load time, but might improve performance scores ” then click on save the change and flush the cache file.
2. W3 Total Cach Plugin Method
W3 total cache and wp super cache are the most famous plugins 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 the object after setting change” and click on save the change and empty the cache
3. Cloudflare Method
If you are using Cloudflare. 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 clicks and clicks on saves the change
4. Wp rocket Method
Wp rocket is one of the most famous premium version plugins used for minification and caching. They too provide the option to remove the 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 are so many plugins in WordPress respiratory but this Query Strings Remover is lightweight and easy 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://www.gomahamaya.com/best-cache-plugins-wordpress/ . That has all feature which is require to optimize any website .