Posted By

cerxx on 12/19/18


Tagged

wordpress


Versions (?)

Remove version of CSS / JS files in WordPress


 / Published in: PHP
 

URL: https://codebeer.ru/ubrat-versiyu-cssjs-fajlov-v-wordpress/

By default, WordPress adds the? Ver = [version] parameter to the end of the address of all connected CSS and JavaScript files. The use of versioning adds a convenient mechanism for monitoring the state of the browser’s cache. After modifying the files, in order for the browser to automatically download the actual versions of CSS or JavaScript, the webmaster simply changes the numeric index ver for the connected file.

Despite the obvious advantages, this method has its drawbacks. One of the main reasons why developers refuse to use versions is that not all proxy servers and CDNs support file caching, at the end of which addresses the ver parameter is specified.

In order to remove ver from the connection string, you need to add the following code to the content of your theme's functions.php file:

  1. function vc_remove_wp_ver_css_js( $src ) {
  2. if ( strpos( $src, 'ver=' ) )
  3. $src = remove_query_arg( 'ver', $src );
  4. return $src;
  5. }
  6. add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
  7. add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: alicetaylor on December 19, 2018

Very helpful advice in this particular post! It’s the little changes that make the largest changes. Thanks for sharing

run 3

You need to login to post a comment.