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.

Remove query strings from static resources

– 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.

Comments (2)

  1. worked perfectly. Checked site on GTmetrix and all ?ver= was removed from js and css src files.

    1. Congratulations Mile !

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Are you human?: