wp_register_style的正确语法?

时间:2016-01-18 00:16:01

标签: php css wordpress

我正在尝试将cache-buster版本添加到我的CSS文件中。

文件说: <?php wp_register_style( $handle, $src, $deps, $ver, $media ); ?>

但是我用谷歌搜索并搜索了这些变量应该格式化的方式。

我正在尝试

 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时增加它?

1 个答案:

答案 0 :(得分:2)

您需要在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

相关问题