4

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.

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.

6
  • can you show the code where you link the style.css file? Commented May 3, 2016 at 10:51
  • its a ready theme, where can i find it? Commented May 3, 2016 at 10:56
  • in your theme folder in the file called functions.php Commented May 3, 2016 at 10:57
  • wp_enqueue_style( 'wp-auth-check' ); its all I found in the functions file. Commented May 3, 2016 at 11:03
  • you can see it in: megawpthemes.com/wordpress/realtor/about-2 see the p style, i changes it in the original file, but it stayed the same... Commented May 3, 2016 at 11:05

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This does nothing for me. Always loading the old style.css?ver=e0a80bacbbe7adc29bd7d945d6748ae8
0

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

2 Comments

While posting an answer please make a practice of adding some description about your answers
This breaks my site (backend, Divi Theme). Still loading, but not working correctly anymore. Probably JS issue.
-1

I recently found this type of need & I got Best Solutions as below for ?ver="1.0.0" etc which will remove version from every css & script.

This may be helpfull in your coding journey.

function theme_remove_script_version( $src ) {
    if ( strpos( $src, 'ver=' ) ) {
        $src = remove_query_arg( 'ver', $src );
    }
    return $src;
}
add_filter( 'script_loader_src', 'theme_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'theme_remove_script_version', 15, 1 );

1 Comment

This appears to be all but identical to the currently highest rated answer that was first published about a decade ago. Is there anything about this which actually makes it better? Or even different?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.