Want to hide the Text Color icon from Visual Editor of WordPress Post Editor from Users other than Admins. How to do it?
1 Answer
This should work if you add it to your functions.php file. It targets the buttons on the second row in your text editor. To target the first row, use the mce_buttons hook instead of mce_buttons_2.
/**
* Removes text color button from tiny mce editor
*/
add_filter( 'mce_buttons_2', 'remove_tiny_mce_buttons');
function remove_tiny_mce_buttons( $buttons ) {
if ( is_admin() && !current_user_can('administrator')){
$remove_buttons = array(
'forecolor', // text color
);
foreach ( $buttons as $button_key => $button_value ) {
if ( in_array( $button_value, $remove_buttons ) ) {
unset( $buttons[ $button_key ] );
}
}
}
return $buttons;
}
If you would like to remove more buttons on the second row (mce_buttons_2), add their IDs to the $remove_buttons array. Below are a few second row IDs:
- formatselect
- underline
- alignjustify
- forecolor
- pastetext
- removeformat
- charmap
- outdent
- indent
- undo
- redo
- wp_help
-
-
Can this code be added to remove other buttons, for e.g: buttons with i class "mce-ico mce-i-et_bloom_shortcode_icon" ?– RiyaCommented Aug 1, 2019 at 15:36
-
I'm glad that helped. I've edited my answer to explain how to remove more than one button, but I'm not sure if that 'bloom' button is affected by the mce_buttons_2 hook.– Louis SCommented Aug 1, 2019 at 20:52
-
So kind of you. Here's the screenshot of the button marked with red arrow ibb.co/fGNq20z and this is the code: <div id="mceu_13" class="mce-widget mce-btn mce-menubtn mce-last" tabindex="-1" aria-labelledby="mceu_13" role="button" aria-label="insert bloom Opt-In" aria-haspopup="true"><button id="mceu_13-open" role="presentation" type="button" tabindex="-1"><i class="mce-ico mce-i-et_bloom_shortcode_icon"></i> <i class="mce-caret"></i></button></div>– RiyaCommented Aug 4, 2019 at 13:52