我正在使用Redux框架创建wp主题,WP-Less用于在LESS中编译样式。在PhpStorm中工作。
现在,我想从Redux中动态更改一些颜色,并将它们传递到将在style.css中编译的主style.less文件。
问题是,当我想要加载我的css时,我需要使用
wp_enqueue_style('my-style', get_stylesheet_uri());但它只加载css,而不是我的less文件。在我的functions.php文件中,我定义了变量。
add_filter('less_vars', 'my_less_vars', 10, 2);函数my_less_vars($vars,$handle) {
Redux::init('redux_qmakeup');
global $redux_qmakeup;
if (isset($redux_qmakeup['opt-typography']['font-family'])) {
$font_name = $redux_qmakeup['opt-typography']['font-family'];
} else {
$font_name = 'Montserrat';
}
if (isset($redux_qmakeup['opt-typography']['color'])) {
$font_color = $redux_qmakeup['opt-typography']['color'];
} else {
$font_color = '#d6451e';
}
if (isset($redux_qmakeup['opt-color-footer'])) {
$footer_color = $redux_qmakeup['opt-color-footer'];
} else {
$footer_color = '#414243';
}
// $handle is a reference to the handle used with wp_enqueue_style()
$vars["font-family"] = "'$font_name'";
$vars["font-color"] = "$font_color";
$vars["footer-color"] = "$footer_color";
return $vars; }在WP-LESS文档中,它说现在我可以在.less文件中使用@footer-color,PhpStorm会自动编译它。但它不会,编译会中断,因为我的@footer-color没有定义。如果我将它定义为一个空变量,它不会采用我的redux颜色,但会保留这个空变量。
发布于 2016-10-12 22:36:08
您正在使用WordPress filter add_filter(' less _vars','my_less_vars',10,2);添加less变量。
我正在使用Netbeans,我确信在PhpStorm中也是如此。Netbeans编译器不能使用WP过滤器,就这么简单。除非所有的变量都是用less文件编写的,否则不能使用PhpStorm编译器进行编译。
一种解决方案是,只有在较少的文件或变量中有一些更改时,才使用WP-LESS编译文件(这些文件或变量将在您更改与其相关的一些主题选项后更改)。
希望这能有所帮助:)
https://stackoverflow.com/questions/40000760
复制相似问题