Skip to content

Instantly share code, notes, and snippets.

@JiveDig
Last active February 24, 2023 06:00
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JiveDig/83c2751199218724fd2a0233c338bb00 to your computer and use it in GitHub Desktop.
Save JiveDig/83c2751199218724fd2a0233c338bb00 to your computer and use it in GitHub Desktop.
Remove buttons/items from the WordPress TinyMCE editor
<?php
/**
* Removes buttons from the first row of the tiny mce editor
*
* @link http://thestizmedia.com/remove-buttons-items-wordpress-tinymce-editor/
*
* @param array $buttons The default array of buttons
* @return array The updated array of buttons that exludes some items
*/
add_filter( 'mce_buttons', 'jivedig_remove_tiny_mce_buttons_from_editor');
function jivedig_remove_tiny_mce_buttons_from_editor( $buttons ) {
$remove_buttons = array(
'bold',
'italic',
'strikethrough',
'bullist',
'numlist',
'blockquote',
'hr', // horizontal line
'alignleft',
'aligncenter',
'alignright',
'link',
'unlink',
'wp_more', // read more link
'spellchecker',
'dfw', // distraction free writing mode
'wp_adv', // kitchen sink toggle (if removed, kitchen sink will always display)
);
foreach ( $buttons as $button_key => $button_value ) {
if ( in_array( $button_value, $remove_buttons ) ) {
unset( $buttons[ $button_key ] );
}
}
return $buttons;
}
/**
* Removes buttons from the second row (kitchen sink) of the tiny mce editor
*
* @link http://thestizmedia.com/remove-buttons-items-wordpress-tinymce-editor/
*
* @param array $buttons The default array of buttons in the kitchen sink
* @return array The updated array of buttons that exludes some items
*/
add_filter( 'mce_buttons_2', 'jivedig_remove_tiny_mce_buttons_from_kitchen_sink');
function jivedig_remove_tiny_mce_buttons_from_kitchen_sink( $buttons ) {
$remove_buttons = array(
'formatselect', // format dropdown menu for <p>, headings, etc
'underline',
'alignjustify',
'forecolor', // text color
'pastetext', // paste as text
'removeformat', // clear formatting
'charmap', // special characters
'outdent',
'indent',
'undo',
'redo',
'wp_help', // keyboard shortcuts
);
foreach ( $buttons as $button_key => $button_value ) {
if ( in_array( $button_value, $remove_buttons ) ) {
unset( $buttons[ $button_key ] );
}
}
return $buttons;
}
@jjbbrr
Copy link

jjbbrr commented Jun 21, 2018

Thanks heaps for this @JiveDig. Note that strikethrough and horizontal line have since moved to the kitchen sink.

@delacosta456
Copy link

hi .. thanks for this .. but please i am newbie in php and wordpress . so my question is
what of if i would like remove button depending of the post_type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment