如果您使用的是经典的TinyMCE编辑器,那么您可能可以修改它并添加自定义样式。
以下代码可以帮助您创建用于添加内联样式的可视按钮。
// Add Formats Dropdown Menu To MCE
if ( ! function_exists( \'mk_style_select\' ) ) {
function mk_style_select( $buttons ) {
array_push( $buttons, \'styleselect\' );
return $buttons;
}
}
add_filter( \'mce_buttons\', \'mk_style_select\' );
// Add new styles to the TinyMCE "formats" menu dropdown
if ( ! function_exists( \'mk_cusotm_styles_dropdown\' ) ) {
function mk_cusotm_styles_dropdown( $settings ) {
// Create array of new styles
$new_styles = array(
array(
\'title\' => __( \'Custom Styles\', \'pixel-text\' ),
\'items\' => array(
array(
\'title\' => __(\'Light\',\'pixel_framework\'),
\'inline\' => \'span\',
\'classes\' => \'light\',
),
array(
\'title\' => __(\'Regular\',\'pixel_framework\'),
\'inline\' => \'span\',
\'classes\' => \'regular\',
),
array(
\'title\' => __(\'Medium\',\'pixel_framework\'),
\'inline\' => \'span\',
\'classes\' => \'medium\',
),
array(
\'title\' => __(\'Bold\',\'pixel_framework\'),
\'inline\' => \'span\',
\'classes\' => \'bold\',
),
),
),
);
// Merge old & new styles
$settings[\'style_formats_merge\'] = true;
// Add new styles
$settings[\'style_formats\'] = json_encode( $new_styles );
// Return New Settings
return $settings;
}
}
add_filter( \'tiny_mce_before_init\', \'mk_cusotm_styles_dropdown\' );