Disable HTML Editor In WordPress

In contrast to the visual editor in WordPress, you can not disable the HTML editor. WordPress does not provide a user setting or a global option. Also, there is no hook, to disable the HTML tab above the editor when writing posts or pages.

But there are users who do not need this tab and like to deactivate it globally. Therefore, I have a solution, how you can disable it in your editor.
Alternatively, you can use the Plugin Adminimize, which offers such a possibility per role, just put it in the settings.

Since there is no hook or an option, you have to hide the area via CSS. This has the disadvantage that, while the tab is no longer visible, but if the cookie or a Plugin says to enable HTML, the editor has a problem showing us either the two editor tabs simultaneously, or no buttons. You need to explicitly set the editor.

In our first step we hide via CSS the tab and the buttons of the HTML editor. This stylesheet must be loaded in the admin, while you can go several ways: either you write it in the header (Hook admin_head) or load an external css via function wp_enqueue_style().

#editor-toolbar #edButtonHTML, #quicktags {
       display: none;
}

The better way is you hide the tab via JavaScript and load this on the Hook admin_footer.

jQuery(document).ready(function($) {
       $("#edButtonHTML").remove();
});

In a further step you must set the default editor, therefore you can use a hook and function, which sets the default to the value tinymce.

function my_default_editor() {
	$r = 'tinymce'; // html or tinymce
	return $r;
}
add_filter( 'wp_default_editor', 'my_default_editor' );

Alternatively, a snippet for the implementation in Plugins or Themes.

add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );

Comments are closed.

10 comments

  1. Dragon Blogger

    Great tip, but who wouldn't want the HTML editor, you can do so much more with it. You can't embed iFrames in the Visual Editor, and in fact the tags break if you switch from HTML to visual editor when you have iframe code in your post.

  2. Greg

    YOU ARE AMAZING. For some reason, my WP install had this odd habit of always defaulting to the HTML view AND hiding all of the buttons. They'd come back if you switched to Visual and back, but it was super annoying.

    You've just put an end to an annoying 2 day search for a solution to this problem. Thank you much!

  3. Jan Schrieber

    I'm trying to turn my on. It seems to be disabled, and I can't figure out why?

  4. Sadie

    I just did this using the Adminimize plugin - http://wordpress.org/extend/plugins/adminimize/

  5. Ryan

    hmm..why would anyone want to disable their html editor?

  6. Steve

    Ryan:
    >> "why would anyone want to disable their html editor?"

    So that clients can't mess up their website once you've handed it over to them! As website designers/developers, the more we can strip out of the dashboard, the simpler it becomes for the client to update, and the less likely they are to muck anything up (incorrect embedding of html tags, poor semantics, etc).

    Obviously as an administrator or more advanced user, the html editor is a good thing to have. But for some end users, it's better that it's not there.

  7. Ryan @ Creating a Website

    I was totally confused about why you'd do this until I just saw the last comment and had an "a ha" moment. Great idea!

3 pingbacks

  1. L’Hebdo WordPress : WordPress 3.0 – Brèves – WordPress Mu – | WordPress Francophone
  2. L’Hebdo WordPress : WordPress 3.0 – Brèves – WordPress Mu –
  3. Set default editor — Wordpress Snippets