我正在尝试向我的 CSS 文件添加一个缓存破坏版本。
文档说:
<?php wp_register_style( $handle, $src, $deps, $ver, $media ); ?>
但我用 Google 搜索并搜索了这些变量的格式化方式。
我在努力
wp_register_style( 'main-css', get_template_directory_uri() . '/style.css', true, 1.5 );
但这始终是 1.5,如:
/wp-content/themes/ofm_1.5/style.css?ver=1.5'
当 css 被编辑后,我如何让它递增?
最佳答案
您需要在 wp_enqueue_style
调用中增加版本值
即:
wp_register_style( 'main-css', get_template_directory_uri() . '/style.css', true, 1.5.1 );
我喜欢做的一件事是使用 filemtime
作为版本:
$ourFile_version = filemtime(dirname(__FILE__). "/style.css");
wp_register_style( 'main-css', get_template_directory_uri() . '/style.css', true, $ourFile_version );
正如另一位成员指出的那样 - 最后一个参数(在您的情况下为 1.5
)是版本号。
https://codex.wordpress.org/Function_Reference/wp_enqueue_style
关于php - wp_register_style 的正确语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34845466/