未附加排队的样式表版本号



>我在浏览器缓存子主题样式表时遇到问题,我需要取消排队/重新注册,然后使用版本号的时间戳重新排队。取消排队然后重新排队工作正常,但无论我尝试什么,都不会附加版本号。我尝试将 wp_enqueue_style() 的版本参数同时设置为 true 和一个字符串。无论如何,都没有将版本号作为查询字符串添加到样式表链接 href 中。我的完整代码片段如下。

function custom_dequeue_enqueue_child_styles() {
    wp_dequeue_style('mk-style');
    wp_deregister_style('mk-style');
    $cacheBuster = filemtime(get_stylesheet_directory() . '/style.css');
    wp_enqueue_style('jupiter-child-stylesheet', get_stylesheet_directory_uri() . '/style.css', array(), $cacheBuster, 'all');
}
add_action( 'wp_enqueue_scripts', 'custom_dequeue_enqueue_child_styles', 999999999);

事实证明,代码确实有效,版本号被剥离的原因是由于隐藏的主题选项,默认情况下会从所有 JS 和 CSS 文件中删除所有版本号。

这是Artbees的Jupiter WordPress主题,主题选项位于"主题选项"中,>"速度优化">"从静态文件查询字符串"。默认情况下,它设置为"关闭",这将删除版本号。将其设置为"On"会将版本号追加为查询字符串参数。这是一个默认启用的非常愚蠢的选项,但现在我们知道了。

最新更新