The mce_buttons_4 WordPress PHP filter allows you to modify the fourth-row list of TinyMCE buttons in the Visual tab of the editor.
Usage
add_filter('mce_buttons_4', 'your_custom_function', 10, 2); function your_custom_function($mce_buttons_4, $editor_id) { // your custom code here return $mce_buttons_4; }
Parameters
- $mce_buttons_4 (array): Fourth-row list of buttons.
- $editor_id (string): Unique editor identifier, e.g. ‘content’. Accepts ‘classic-block’ when called from block editor’s Classic block.
More information
See WordPress Developer Resources: mce_buttons_4
Examples
Add a custom button to the fourth row
Add a custom button named ‘My Button’ to the fourth row of the TinyMCE toolbar.
add_filter('mce_buttons_4', 'add_custom_button', 10, 2); function add_custom_button($mce_buttons_4, $editor_id) { $mce_buttons_4[] = 'my_button'; return $mce_buttons_4; }
Remove the ‘code’ button from the fourth row
Remove the ‘code’ button from the fourth row of the TinyMCE toolbar.
add_filter('mce_buttons_4', 'remove_code_button', 10, 2); function remove_code_button($mce_buttons_4, $editor_id) { $key = array_search('code', $mce_buttons_4); if ($key !== false) { unset($mce_buttons_4[$key]); } return $mce_buttons_4; }
Reorder buttons in the fourth row
Change the order of buttons in the fourth row of the TinyMCE toolbar.
add_filter('mce_buttons_4', 'reorder_buttons', 10, 2); function reorder_buttons($mce_buttons_4, $editor_id) { $new_order = array('code', 'hr', 'forecolor'); return $new_order; }
Add a button only for the Classic block
Add a custom button named ‘Classic Only Button’ to the fourth row of the TinyMCE toolbar, only for the Classic block.
add_filter('mce_buttons_4', 'add_classic_only_button', 10, 2); function add_classic_only_button($mce_buttons_4, $editor_id) { if ($editor_id === 'classic-block') { $mce_buttons_4[] = 'classic_only_button'; } return $mce_buttons_4; }
Remove all buttons from the fourth row
Remove all buttons from the fourth row of the TinyMCE toolbar.
add_filter('mce_buttons_4', 'remove_all_buttons', 10, 2); function remove_all_buttons($mce_buttons_4, $editor_id) { return array(); }