Remove query strings from static resources
I was looking for a way to remove query strings using a function while testing my site performance using gtmetrix.com
I kept getting a low score due to query strings in static resources and a message such as:
Remove query strings from static resources.
So after a bit of research and playing around with the code I managed to get a 100% score and no error using this code:
Code:
//remove all query strings from script and css files.
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 );
Just drop it in at the bottom of your child-theme functions.php file
I would normally charge £10,000 pounds for this fix but you can have it for nothing.