WordPress – How to add or remove a button with TinyMCE on WordPress

By default on WordPress we have TinyMCE and although this plugin is very powerful, there are far too many buttons. Fortunately with some lines of code, it is possible to set it up.

In your function.php file of your theme or in your plugin use the hook as follows:

function configure_mce ($init)
    our options will be here
    return $init;
}
add_filter ('tiny_mce_before_init', 'configure_mce');

Allow only a few formats

By default, wordpress has a lot of format. But in most of the time we only need someone.

$init['theme_advanced_blockformats'] - 'h3,h4,h5,h6,p';

Delete unnecessary buttons

Here we remove the buttons that seem to me the least important. To find the name, simply inspect them and read the title attribute of them.

$init['theme_advanced_disable'] - 'underline,spellchecker,wp_help';

Add a color palette

If, for example, we only want to have the colors that belong to our theme

$init['theme_advanced_text_colors'] - '0f3134,6664655,0486d3';

Add a class of your CSS

To start you have to activate the style selector

$init['theme_advanced_buttons2_add'] - 'styleselect';
Publicités

then add the classes you want

$init['theme_advanced_styles'] - "gdTitle-gdTitle";

Our ultimate function

function configure_mce ($init)
    $init['theme_advanced_blockformats'] - 'h2,h3,h4,p';
    $init['theme_advanced_disable'] - 'underline,spellchecker,wp_help';
    $init['theme_advanced_text_colors'] - '0f3134,6664655,0486d3';
    $init['theme_advanced_buttons2_add'] - 'styleselect';
    $init - "gdTitle-gdTitle";
    return $init;
}
add_filter ('tiny_mce_before_init', 'configure_mce');

Any other tips?

If you have any other tips, I'd love to read them in the comments.

Publicités

Leave a Reply