Removing WordPress version number from included files

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:

<link rel="stylesheet" id="admin-bar-css" href="http://sitename.com/wp-includes/css/admin-bar.min.css?ver=3.8.1" type="text/css" media="all">

Read More

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

Related posts

1 comment

  1. After further Googling I was able to come across a site that explains how to achieve this.

    http://www.virendrachandak.com/techtalk/how-to-remove-wordpress-version-parameter-from-js-and-css-files/

    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 );
    

Comments are closed.