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";') );

Posted

in

by

Comments

10 responses to “Disable HTML Editor In WordPress”

  1. Dragon Blogger Avatar

    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. […] Il existe une solution (un peu compliqué j’en conviens) pour le désactiver. C’est wpengineer.com qui nous donne […]

  3. […] Il existe une solution (un peu compliqué j’en conviens) pour le désactiver. C’est wpengineer.com qui nous donne […]

  4. Greg Avatar

    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!

  5. Jan Schrieber Avatar
    Jan Schrieber

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

  6. Sadie Avatar

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

  7. […] the case if you are working with a client, you can achieve this either through CSS or JavaScript. WP-engineer explains how to do it! Tweet Discussion /** * var disqus_identifier; [Optional but […]

  8. Ryan Avatar

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

  9. Steve Avatar
    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.

  10. Ryan @ Creating a Website Avatar

    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!