X

Disable Tinymce HTML editor for everyone but admin

Ninja Forms Review - more options

Adding this snippet to the functions.php of your wordpress theme will disable the Tinymce HTML editor for everyone but the admin.



Code Snippet:


add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
add_action( 'admin_head', 'disable_html_editor_wps' );
function disable_html_editor_wps() {
global $current_user;
get_currentuserinfo();
if ($current_user->user_level != 10) {
echo '<style type="text/css">#editor-toolbar #edButtonHTML, #quicktags {display: none;}</style>';
}
}

Comments  Leave a Reply

  1. WordPress Conditional Tags (And Snippets) for Beginners March 7, 2015 at 5:44 am

    […] [Source] […]

  2. Disable and display:none; aren’t really the same thing…

  3. Fredrik Persson May 27, 2014 at 10:02 am

    It seems that you can use firedebug and enable it again and use it and still write javascript.
    Not safe.

  4. Nice snippet. I had to use the following CSS to make this work: a#content-html {display: none !important;}

  5. Avinash D'Souza January 8, 2013 at 9:22 am

    Hey Kevin,

    I’d really love to see this code still being active…any chance of an update for WP 3.5?

    As of now, I don’t see this working…

    1. Avinash D’Souza:
      this works for me! – replace the style part for this:

      html.wp-toolbar
      body.wp-admin div#wpwrap div#wpcontent div#wpbody div#wpbody-content
      div.wrap form#post div#poststuff div#post-body.metabox-holder
      div#post-body-content div#postdivrich.postarea
      div#wp-content-wrap.wp-core-ui
      div#wp-content-editor-tools.wp-editor-tools
      a#content-tmce.wp-switch-editor

  6. Hey Kevin — great snippet and learned from it as I do from most of your code. Bizarre follow up, how can we disable the text area altogether? WHAT!!!! LOL
    Ok, I have a custom post type with nothing but custom fields for entry (using the custom fields template plugin) and all the cod is in the custom post php template. I know it has something to do with ‘display: none’  but don’t know what the “display” code is. I think I can put it in a separate style sheet with add_editor_style and use an if (is_singular) condition to show only on the custom post.

    Thanks

    1. Hi Mike, you can remove the Editor from the custom post type by removing that options from the supports array within your custom post type code.

      ‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘custom-fields’, ‘thumbnail’ ),

  7. Thanks, just what i needed.

    1. Cool glad I could be of help.

  8. Thanks, helpful!

    1. Glad to help nick,

  9. Any way to make this user specific?

    1.  Yep you could do something like this, should work. Using a list of people within an array and check against the current user. If the users not in the $users array you remove HTML editor.

      add_filter( ‘wp_default_editor’, create_function(”, ‘return “tinymce”;’) );
      add_action( ‘admin_head’, ‘disable_html_editor_wps’ );
      function disable_html_editor_wps() {

          global $current_user;
          get_currentuserinfo();

          $users = array(“dave”, “larry”, “steve”, “ryan”);

          if (!in_array($current_user->user_login, $users)) {
              echo ‘#editor-toolbar #edButtonHTML, #quicktags {display: none;}’;
          }
      }

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!