We have all been there. You finish up the most beautiful design with perfectly picked colours, font sizes and page style and pass it off to the client. A few days later you check back at the site and they have happily splattered underlined neon green h1 tags with inline styles. Why why why? Because the WordPress WYSIWYG editor is hard to use and by default it temps you with a basic colour pallet and basic h1-h6 tags.
Not to worry! With a few lines of code we can remove the harmful parts of TinyMCE and supply a few useful features! Pop open your theme's functions.php file and create a basic function and hook like this:
function make_mce_awesome( $init ) {
// our Options will go here..
return $init;
}
add_filter('tiny_mce_before_init', 'make_mce_awesome');
$init['theme_advanced_blockformats'] = 'h3,h4,h5,h6,p';
$init['theme_advanced_disable'] = 'underline,spellchecker,wp_help';
$init['theme_advanced_text_colors'] = '0f3156,636466,0486d3';
$init['theme_advanced_buttons2_add'] = 'styleselect';
Then you can specify a list of labels and associated CSS classes.
$init['theme_advanced_styles'] = "bigTitle=bigTitle;Call To Action Button=ctaButton,Rounded Corners=rounded";
Our Final function looks like this:
function make_mce_awesome( $init ) {
$init['theme_advanced_blockformats'] = 'h2,h3,h4,p';
$init['theme_advanced_disable'] = 'underline,spellchecker,wp_help';
$init['theme_advanced_text_colors'] = '0f3156,636466,0486d3';
$init['theme_advanced_buttons2_add'] = 'styleselect';
$init['theme_advanced_styles'] = "bigTitle=bigTitle;Call To Action Button=ctaButton,Rounded Corners=rounded";
return $init;
}
add_filter('tiny_mce_before_init', 'make_mce_awesome');
add_editor_style('editor-style.css');
I found that passing in editor-style.css (which should be found in the root of your theme) busted any cache that add_editor_style() was giving me.
Find an issue with this post? Think you could clarify, update or add something?
All my posts are available to edit on Github. Any fix, little or small, is appreciated!