WordPress – Remove Version Number From CSS

I am using a wordpress theme, and the css file uploads with version number:
style.css?ver=1.2.8

The problem is that when i change the css file, the browser keep loading the file without my changes. I can see that the changes were saved on the server, but nothing help to load the right file.

Read More

I tried:

function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
    $src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );

But everything disappeared.

I read the other topics on the subject but nothing helped.

Thank you.

Related posts

2 comments

  1. That below given code may help you.

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

    Taken from https://wordpress.stackexchange.com/questions/132282/removing-wordpress-version-number-from-included-files

    That works for me, hope it will work for you as well.

  2. Add this code to the functions.php of your theme.

    function remove_file_version($src){
        return preg_replace("/?ver=[0-9.]+/", "", $src);
    }
    
    add_filter('style_loader_src', 'remove_file_version', 100);
    add_filter('script_loader_src', 'remove_file_version', 100);
    

Comments are closed.