Yogesh Chauhan's Blog

How to remove WordPress TinyMCE Editor buttons?

in WordPress on June 10, 2021

WordPress has some hooks if you want to remove some of the buttons or even adjust the Header tags.

Remove H1 Option


function yc_remove_h1_TinyMCE( $in ) {
  $in['block_formats'] = 
    "Paragraph=p; 
    Heading 2=h2; 
    Heading 3=h3; 
    Heading 4=h4; 
    Heading 5=h5; 
    Heading 6=h6;
    Preformatted=pre";
  return $in;
}
add_filter( 'tiny_mce_before_init', 'yc_remove_h1_TinyMCE' );


You can just remove the other Header tags if you don’t need them and leave the paragraph tag!

Removes buttons from the first row

This is how you can remove the buttons from the first row of the tinyMCE editor.


add_filter( 'mce_buttons', 'yc_remove_tiny_mce_buttons_first_row');
function yc_remove_tiny_mce_buttons_first_row( $buttons ) {

    $remove_buttons = array(
        'bold',
        'italic',
        'strikethrough',
        'bullist',
        'numlist',
        'blockquote',
        '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


add_filter( 'mce_buttons_2', 'yc_remove_tiny_mce_buttons_second_row');
function yc_remove_tiny_mce_buttons_second_row( $buttons ) {

    $remove_buttons = array(
        'formatselect', // dropdown menu for p and header tags
        '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;
}


More Resources


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Select statement in Postgres with examplesPostgresHow to make a web page look good on any device?HTMLHow to set default timezone using PHP?PHPWhat is HTMLUnknownElement?HTMLHow to add a Bar Chart in Angular App?AngularHow to swap images on hover using CSS?CSS