I have added some custom styles to the TinyMCE editor using the tiny_mce_before_init
filter hook. They work by adding classes to the block-level element. See the code below:
function byron_mce_before_init($settings) {
$style_formats = [
[
'title' => 'Lead',
'block' => 'p',
'classes' => 'lead',
],
[
'title' => 'Tagline',
'block' => 'h5',
'classes' => 'tagline',
],
];
$settings['style_formats'] = json_encode($style_formats);
return $settings;
}
add_filter('tiny_mce_before_init', 'byron_mce_before_init');
The problem I am having, is that when switching between the styles defined above, the class is not removed; in stead, the new class is appended to the old class in stead of replacing it. I can’t seem to figure out how to remove the old classes when switching between styles. Any help would be greatly appreciated.