Skip to content

Instantly share code, notes, and snippets.

@verticalgrain
Created March 27, 2015 19:15
Show Gist options
  • Select an option

  • Save verticalgrain/9e5a4eceae19b5b5a887 to your computer and use it in GitHub Desktop.

Select an option

Save verticalgrain/9e5a4eceae19b5b5a887 to your computer and use it in GitHub Desktop.
Wordpress editor template functions - customize the Wordpress WYSIWYG TinyMCE editor
<?php
// Remove default buttons from the first row of editor buttons in the Wordpress WYSIWYG editor
add_filter( 'mce_buttons', 'remove_unnecessary_editor_buttons_mce');
function remove_unnecessary_editor_buttons_mce( $buttons ) {
$invalid_buttons = array(
// 'bold',
// 'italic',
'strikethrough',
// 'bullist',
// 'numlist',
// 'blockquote',
'hr',
// 'alignleft',
// 'aligncenter',
// 'alignright',
// 'link',
// 'unlink',
'wp_more',
'fullscreen',
'wp_adv'
);
foreach ( $buttons as $button_key => $button_value ) {
if ( in_array( $button_value, $invalid_buttons ) ) {
unset( $buttons[ $button_key ] );
}
}
return $buttons;
}
// Remove default buttons from the second row of editor buttons (Kitchen sink) in the Wordpress WYSIWYG editor
add_filter( 'mce_buttons_2', 'remove_unnecessary_editor_buttons_mce2');
function remove_unnecessary_editor_buttons_mce2( $buttons ) {
$invalid_buttons = array(
// 'mce-menubtn',
'underline',
'justifyfull',
'forecolor',
'|',
'pastetext',
'pasteword',
'removeformat',
'charmap',
'outdent',
'indent',
'undo',
'redo',
'wp_help',
'alignjustify'
);
foreach ( $buttons as $button_key => $button_value ) {
if ( in_array( $button_value, $invalid_buttons ) ) {
unset( $buttons[ $button_key ] );
}
}
return $buttons;
}
// Force the kitchen sink to always be on
// Caution - this might flood your basement
add_filter( 'tiny_mce_before_init', 'force_kitchensink_open' );
function force_kitchensink_open( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
// Modifying items that appear in the Format dropdown list, on the left hand side of second row of editor buttons
function mce_mod( $init ) {
$init['block_formats'] = "H1 Title (Largest, bold)=h1; H2 Title (Large)=h2; H3 Title (Medium, bold)=h3; Paragraph (Regular Text)=p; Blockquote Style 1 (Green text)=h4; Blockquote Style 2=blockquote;";
return $init;
}
add_filter('tiny_mce_before_init', 'mce_mod');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment