Are you looking for a way to disable the TinyMCE HTML editor for everyone but the admin? While there’s probably a plugin for this, we have created a quick code snippet that you can use to disable TinyMCE HTML editor for everyone but admin in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
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>'; } }
Alternatively you could use this snippet, which will disable TinyMCE for everyone but the specified list of users. Add this code to your theme’s functions.php file or in a site-specific plugin.
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(); // change users in list $users = array( "dave", "larry", "steve", "ryan" ); if (!in_array($current_user->user_login, $users)) { echo '<style type="text/css">#editor-toolbar #edButtonHTML, #quicktags {display: none;}</style>'; } }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 27 best WordPress business themes for your website and how to set up download tracking in WordPress with Google Analytics.
[…] [Source] […]
Disable and display:none; aren’t really the same thing…
It seems that you can use firedebug and enable it again and use it and still write javascript.
Not safe.
Nice snippet. I had to use the following CSS to make this work: a#content-html {display: none !important;}
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…
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
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
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’ ),
Thanks, just what i needed.
Cool glad I could be of help.
Thanks, helpful!
Glad to help nick,
Any way to make this user specific?
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;}’;
}
}