Many JAVASCRIPT and CSS files in WordPress have the WordPress version number appended to their URL. In this post, I will show how we can remove the version number from JS and CSS URL in WordPress.
We can use one of the following 2 methods. Just add the code for one of the below methods in your theme’s functions.php file.
Method 1
Remove the “ver” parameter from all WordPress enqueued CSS and JAVASCRIPT files.
// remove wordpress version param from any enqueued scripts
function wcb_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );
Method 2
Remove only the “ver” parameter only if its value matches the WordPress version number from all WordPress enqueued CSS and JS files.
// remove wordpress version param from any enqueued scripts
function wcb_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'wcb_remove_wp_ver_css_js', 9999 );
Important Notes
Some WordPress Plugins depend on the ver query string parameter for some internal maintenance. So removing it may cause issues with the functioning of those plugins. If adding the above code causes issues with any of the plugins on your site, then add this code instead.
This will only remove the ver parameter added by WordPress.