LESSでスタイルをコンパイルするためのReduxフレームワーク、WP-Lessを使用してwpテーマを作成しています。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);
function 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 の色は使用されませんが、その空の変数は保持されます。