删除WordPress中CSS/JS文件的版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了删除WordPress中CSS/JS文件的版本相关的知识,希望对你有一定的参考价值。

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

以上是关于删除WordPress中CSS/JS文件的版本的主要内容,如果未能解决你的问题,请参考以下文章

wordpress 的本地主机:链接参考 css/js 文件的正确方法?

WordPress引入css/js两种方法

Wordpress Migration失去了.css,.js等主要信息

WordPress删除任意文件/执行任意代码安全漏洞临时修复方法

杨泽业:wordpress中的历史版本如何删除?

wordpress 移动主题删除简码