How to remove WordPress version parameter after JS and CSS scripts
Remove query strings from static resources like style sheet and java script is one of several steps to optimize your website. This tutorial will show you how to remove WordPress version parameter after JS and CSS scripts which will help caching and speed up your website.
– Before start, go to http://tools.pingdom.com
to analyze your website
– After done click to “Performance Grade” tab and “Remove query strings from static resources” dropdown.
– Now back to your site then open your function.php in current theme and paste this code to your file:
// remove wp version param from any enqueued scripts
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
– Click save and Refresh your site. Now you can back to tools.pingdom.com and test it again.
worked perfectly. Checked site on GTmetrix and all ?ver= was removed from js and css src files.
Congratulations Mile !