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 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to verify your domain in Google Console with a TXT record?MiscellaneousHow to Install PHP Laravel on MacOS Catalina?PHPWordPress: How to loop through ACF group fields?WordPressJavaScript String Properties and MethodsJavaScriptWhat are Null Sessions?Miscellaneous5 Key Principles Of Good Website UsabilityUI/UX