YogeshChauhan . com

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

amazon

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 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

What’s a repository on Github?MiscHow to add and remove list items using JavaScript?JavaScriptINNER JOIN in PostgresPostgresHow to merge arrays in JavaScript?JavaScriptThe substr() method in JavaScript and how it’s different from substring()JavaScriptHow to create a full screen loader using CSS and JavaScript?CSS