我在函数中使用以下代码。php文件添加一个格式下拉菜单到WordPress可视化编辑器,只需一个选项,自定义1。
<?php
function custom_styles_button($buttons) {
array_unshift($buttons, \'styleselect\');
return $buttons;
}
add_filter(\'mce_buttons_2\', \'custom_styles_button\');
function my_mce_before_init_insert_formats( $init_array ) {
// Define the style_formats array
$style_formats = array(
// Each array child is a format with it\'s own settings
array(
\'title\' => \'Custom 1\',
\'block\' => \'span\',
\'classes\' => \'custom-1\',
\'wrapper\' => true,
),
);
// Insert the array, JSON ENCODED, into \'style_formats\'
$init_array[\'style_formats\'] = json_encode( $style_formats );
return $init_array;
}
// Attach callback to \'tiny_mce_before_init\'
add_filter( \'tiny_mce_before_init\', \'my_mce_before_init_insert_formats\' );
function add_editor_styles() {
add_editor_style( \'editor-style.php\' );
}
add_action( \'init\', \'add_editor_styles\' );
我的编辑。php包含以下代码;<?php
header("Content-type: text/css");
$test = \'#006699\';
?>
.custom-1 {
color : <?php echo $test ?>;
}
因此,当我在WordPress可视化编辑器中选择一段文本并将其自定义为-1时,它在可视化编辑器中的颜色将变为#006699。这很好。然而,我希望能够从定制器中动态控制颜色,我正在使用Kirki框架以编辑器样式选择颜色和代码。php看起来像;<?php
$test = get_theme_mod( \'graviton_custom_1_text_color\', \'#FFFFFF\' );
header("Content-type: text/css");
?>
.custom-1 {
color : <?php echo $test ?>;
}
但这不起作用,在可视化编辑器的“自定义格式”下拉列表中,“自定义1选择”保持高亮显示,文本颜色保持黑色。我知道代码;$test = get_theme_mod( \'graviton_custom_1_text_color\', \'#FFFFFF\' );
确实在$test中正确地输入了正确的颜色值,但我不理解为什么在使用相同的变量时,它不遵循样式。