Removing WordPress version number from included files [duplicate]
IT Nursery
May 19, 2022
0
I am trying to remove the WordPress version number from the file extensions for security purposes. Some of the enqueued files include the WordPress version number on the end of them, which can be seen from the inspector. For example:
As you can see, ver=3.8.1 was apended. I’ve come across a few filters that remove the WordPress version number from the header and footer etc, but not from the included files. That filter looks like:
function remove_version() {
return '';
}
add_filter('the_generator', 'remove_version');
But that does not remove the version number from linked files. Does any one know of a way to remove this version number??
Thanks
1 Answer 1
After further Googling I was able to come across a site that explains how to achieve this.
The second function on the page is quite helpful. This looks for “ver=” and checks that it matches the WordPress version number and then removes it. The first function on the page removes all version numbers from all files.
The function that achieved the results looks like:
// remove wp version param from any enqueued scripts
function vc_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', 'vc_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );