Skip to content

Instantly share code, notes, and snippets.

@cr0ybot
Created August 30, 2017 13:51
Show Gist options
  • Save cr0ybot/18f1eeaa7215f8072f29c024d7082563 to your computer and use it in GitHub Desktop.
Save cr0ybot/18f1eeaa7215f8072f29c024d7082563 to your computer and use it in GitHub Desktop.
Add style formats to WordPress editor dropdown
function my_mce_before_init_insert_formats( $init_array ) {
$style_formats = array(
array(
'title' => 'Headline',
'block' => 'h2',
'classes' => 'headline',
'wrapper' => false,
),
array(
'title' => 'Blockquote',
'block' => 'blockquote',
'classes' => '',
'wrapper' => false
),
array(
'title' => 'Button link',
'selector' => 'a',
'classes' => 'button',
'wrapper' => false
),
array(
'title' => 'CTA Button link',
'selector' => 'a',
'classes' => 'cta',
'wrapper' => false
)
);
// Insert the array, JSON ENCODED, into 'style_formats'
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment