0

Want to hide the Text Color icon from Visual Editor of WordPress Post Editor from Users other than Admins. How to do it?

3
  • Hi @Riya - Is this for Classic Editor or Gutenberg?
    – Louis S
    Commented Jul 29, 2019 at 12:43
  • @LouisS Classic Editor
    – Riya
    Commented Jul 30, 2019 at 16:04
  • Ok, let me know if my answer below works.
    – Louis S
    Commented Jul 30, 2019 at 18:16

1 Answer 1

0

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
4
  • Thanks it worked
    – Riya
    Commented Aug 1, 2019 at 14:37
  • Can this code be added to remove other buttons, for e.g: buttons with i class "mce-ico mce-i-et_bloom_shortcode_icon" ?
    – Riya
    Commented 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 S
    Commented 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>
    – Riya
    Commented Aug 4, 2019 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.