Remove static resources query strings

List of errors

Query strings are unnecessary for static files like JS and CSS because they do not process the parameters passed to them. WordPress put them there so that when you update WordPress version the old file will not be cached and you immediately get the updated version.

To find out if your site is suffering from unnecessary query strings from static resources. Go have your site test out at pingdom. From the test, my default WordPress theme is having a bad score of “E”.

remove static resources query strings
A list of static resources query strings errors.

 Remove static resources query strings

There is WordPress plugin to fix this but I dislike the fact that there are so many badly written plugins that will damage my WordPress site. Therefore I prefer to fix it the PHP way.

To fix it, go to the functions.php file within the folder of your theme and add the following codes at the end of the file. What the codes do is that it is splitting the URL using “?” as the delimiter and then choose the first part of it.

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

Successfully fixed

Once fixed, have your site retested again. It should now have a score of “A”.

remove static resources query strings
Reran the test after fixing it.