WordPress.org

Ready to get started?Download WordPress

Codex

Plugin API/Filter Reference/mce buttons, mce buttons 2, mce buttons 3, mce buttons 4

Contents

Description

The mce_buttons group of filters can be used by developers to add or remove buttons/features from the WordPress's TinyMCE toolbar(s).

This filter is passed an array of button ids which determine which buttons are displayed or removed.

Filter Descriptions

Four filter hooks are available:

mce_buttons 
The primary toolbar (always visible)
mce_buttons_2 
The advanced toolbar (can be toggled on/off by user)
mce_buttons_3 
By default, WordPress does not use/display this toolbar
mce_buttons_4 
By default, WordPress does not use/display this toolbar

Example

Reveal a hidden button

The following will reveal the hidden "Styles" dropdown in the advanced toolbar.

function myplugin_tinymce_buttons($buttons)
 {
      //Add style selector to the beginning of the toolbar
      array_unshift($buttons, 'styleselect');

      return $buttons;
 }
add_filter('mce_buttons_2','myplugin_tinymce_buttons');

Remove a button

The following will remove the text color selector from the advanced toolbar.

function myplugin_tinymce_buttons($buttons)
 {
      //Remove the text color selector
      $remove = 'forecolor';

      //Find the array key and then unset
      if ( ( $key = array_search($remove,$buttons) ) !== false )
		unset($buttons[$key]);

      return $buttons;
 }
add_filter('mce_buttons_2','myplugin_tinymce_buttons');

Or, if you want to remove more buttons at the same time:

function myplugin_tinymce_buttons($buttons)
 {
	//Remove the format dropdown select and text color selector
	$remove = array('formatselect','forecolor');

	return array_diff($buttons,$remove);
 }
add_filter('mce_buttons_2','myplugin_tinymce_buttons');

External Resources

Related