Remove version of CSS / JS files in WordPress


/ Published in: PHP

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:


Copy this code and paste it in your HTML
  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 );

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.