WordPress has a custom configuration of TinyMCE built-in for rich text editing. On many occasions I’ve found it useful to trim down the editor buttons and format options in the WordPress TinyMCE WYSIWYG editor to make content management and publishing easier for writers and editor.
Here’s the set of options that I use on most of my WordPress setups. Feel free to customize this, I’ve included the default array values in each function. To get started, add the following functions to your theme’s functions.php file.
// TinyMCE: First line toolbar customizations
if( !function_exists('base_extended_editor_mce_buttons') ){
function base_extended_editor_mce_buttons($buttons) {
// The settings are returned in this array. Customize to suite your needs.
return array(
'formatselect', 'bold', 'italic', 'sub', 'sup', 'bullist', 'numlist', 'link', 'unlink', 'blockquote', 'outdent', 'indent', 'charmap', 'removeformat', 'spellchecker', 'fullscreen', 'wp_more', 'wp_help'
);
/* WordPress Default
return array(
'bold', 'italic', 'strikethrough', 'separator',
'bullist', 'numlist', 'blockquote', 'separator',
'justifyleft', 'justifycenter', 'justifyright', 'separator',
'link', 'unlink', 'wp_more', 'separator',
'spellchecker', 'fullscreen', 'wp_adv'
); */
}
add_filter("mce_buttons", "base_extended_editor_mce_buttons", 0);
}
// TinyMCE: Second line toolbar customizations
if( !function_exists('base_extended_editor_mce_buttons_2') ){
function base_extended_editor_mce_buttons_2($buttons) {
// The settings are returned in this array. Customize to suite your needs. An empty array is used here because I remove the second row of icons.
return array();
/* WordPress Default
return array(
'formatselect', 'underline', 'justifyfull', 'forecolor', 'separator',
'pastetext', 'pasteword', 'removeformat', 'separator',
'media', 'charmap', 'separator',
'outdent', 'indent', 'separator',
'undo', 'redo', 'wp_help'
); */
}
add_filter("mce_buttons_2", "base_extended_editor_mce_buttons_2", 0);
}
This is the code I use to remove the H1 from the Format dropdown in the editor. You can add whatever tags you like here, just as long as they are block-level elements.
// Customize the format dropdown items
if( !function_exists('base_custom_mce_format') ){
function base_custom_mce_format($init) {
// Add block format elements you want to show in dropdown
$init['theme_advanced_blockformats'] = 'p,h2,h3,h4,h5,h6,pre';
// Add elements not included in standard tinyMCE dropdown p,h1,h2,h3,h4,h5,h6
//$init['extended_valid_elements'] = 'code[*]';
return $init;
}
add_filter('tiny_mce_before_init', 'base_custom_mce_format' );
}