Skip to content

Instantly share code, notes, and snippets.

@joemcgill
Last active October 14, 2016 08:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joemcgill/7171061 to your computer and use it in GitHub Desktop.
Save joemcgill/7171061 to your computer and use it in GitHub Desktop.
Set of functions for easily customizing the tinyMCE editor in WordPress. More references: Wes Bos – http://wesbos.com/custom-wordpress-tinymce-wysiwyg-classes/ TinyMCE Reference – http://www.tinymce.com/wiki.php/TinyMCE3x:Buttons/controls
// add style selector drop down
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
add_filter( 'mce_buttons_2', 'my_mce_buttons_2' );
// customize the MCE editor
function my_customize_mce( $init ) {
/* Only include these tags */
$init['theme_advanced_blockformats'] = 'h2,h3,h4,p';
/* Remove these buttons */
$init['theme_advanced_disable'] = 'forecolor, underline, justifyfull, indent, outdent'; /*
/* Set up your custom style classes */
$style_formats = array(
array(
'title' => 'Intro Paragraph',
'selector' => 'p',
'classes' => 'lead'
),
);
/* Only include your custom styles -- defined above -- in your style dropdown */
$init['style_formats'] = json_encode( $style_formats );
return $init;
}
add_filter('tiny_mce_before_init', 'my_customize_mce');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment