Remove version from css & js files in WordPress

In this post I will show how we can remove the version number from CSS & JS files.

Many css and js files in the WordPress have the WordPress version number appended to their source. Therefore to improve the speed of website as much as possible we need to remove query strings from css and js files. When we analyze site’s page using any page speed analyzer such as Google’s Page Speed, YSlow or Pingdom, we are very likely to see suggestions to remove query strings from css and js files. This is a problem as many proxies will not cache the resources if it has a query string in the URL.
Add the below code to your theme’s functions.php file

function remove_wp_ver_css_js( $src ) {
    if ( strpos( $src, 'ver=' ) )
        $src = remove_query_arg( 'ver', $src );
    return $src;
}
add_filter( 'style_loader_src', 'remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'remove_wp_ver_css_js', 9999 );

Thanks for reading.

Soumitra Roy Sarkar

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on JEE Tutorials Twitter Facebook  Google Plus Linkedin Or Email Me

Leave a Reply

Your email address will not be published. Required fields are marked *