我创建了一个TinyMCE
风格dropdown
对于TinyMCE
WordPress编辑器。
这些格式在编辑器上按预期显示,但当下拉菜单展开以从样式中选择时,它们显示为已禁用-是否有任何原因?我的代码附在下面。
function new_mce_button($buttons) {
array_unshift($buttons, \'styleselect\');
return $buttons;
}
add_filter(\'mce_buttons_2\', \'new_mce_button\');
/**
* Callback function to filter the MCE settings
*/
function custom_formats( $init_array ) {
$style_formats = array(
array(
\'title\' => \'White Button\',
\'selector\' => \'a\',
\'classes\' => \'cta wht\',
),
array(
\'title\' => \'Grey Button\',
\'selector\' => \'a\',
\'classes\' => \'cta gry\'
),
array(
\'title\' => \'Light Blue Button\',
\'selector\' => \'a\',
\'classes\' => \'cta lblue\'
),
array(
\'title\' => \'Dark Blue Button\',
\'selector\' => \'a\',
\'classes\' => \'cta dblue\'
),
);
$init_array[\'style_formats\'] = json_encode( $style_formats );
return $init_array;
}
add_filter( \'tiny_mce_before_init\', \'custom_formats\' );
最合适的回答,由SO网友:estin92 整理而成
正如@karun所指出的,首先需要将文本制作成超链接,然后再激活格式。
将数组值更改为
array(
\'title\' => \'Grey Button\',
\'block\' => \'div\',
\'classes\' => \'cta gry\'
),
使样式永久可用。