I want to add custom styles to WordPress using dynamic arrays.
My question is how can I add the two arrays to the style_formats array within the ‘my_mce_before_init_insert_formats’ function dynamically?
I’ve tried using array_merge(), and a few other dynamic array techniques but it just resets the TinyMCE editor to its default settings or breaks it completely.
function my_mce_before_init_insert_formats( $init_array ) {
$style_formats = array(
array(
'title' => '.translation',
'block' => 'blockquote',
'classes' => 'translation',
'wrapper' => true,
),
//add arrays here
);
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
//arrays to add
array(
'title' => '⇠.rtl',
'block' => 'blockquote',
'classes' => 'rtl',
'wrapper' => true,
),
array(
'title' => '.ltr⇢',
'block' => 'blockquote',
'classes' => 'ltr',
'wrapper' => true,
),