wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Disable Tinymce HTML editor for everyone but admin

wordpress snippet

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

snippet :  PHPcopy
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>';
	}
}

Did you like this post? If so please share it with your friends. Thanks!

  • Anonymous

    Any way to make this user specific?

    • http://wpsnipp.com Kevin Chard

       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;}';
          }
      }

  • Nick

    Thanks, helpful!

    • http://wpsnipp.com Kevin Chard

      Glad to help nick,

  • Braamsviper

    Thanks, just what i needed.

    • http://wpsnipp.com Kevin Chard

      Cool glad I could be of help.

  • Mike

    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

    • http://wpsnipp.com Kevin Chard

      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’ ),

  • http://www.avinashdsouza.me Avinash D’Souza

    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…

    • mano

      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

  • steve

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

  • Fredrik Persson

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

  • Ben

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