Disable Visual Editing in WordPress

By default in WordPress, any registered users gets the privilege to edit or add content using the “Visual” mode or the “Rich Text Editing” screen. This is also known as “WYSIWYG” editor. Even though there are ways to disable this feature manually (see Users > Your Profile page), you as a site admin can take advantage of little snippet to customize or to enforce this feature anyway you want.

WordPress Visual Editor TabWordPress Visual Editor Tab.

Disable for All

Simply add the following snippet on your current theme’s functions.php file and update the page.

<?php 
add_filter('user_can_richedit',create_function('','return false;'),50);
?>

Now, lets not forget that this snippet would force everyone to use the “text” mode.

Disable for All but Yourself

As a site admin, you may want to have the visual editing privilege for yourself but not for others. In that case we got to be little tricky with our snippet. Let’s take a look at the following snippet.

<?php
function disable_visual_editor(){
   $cuser = wp_get_current_user();
   if ($cuser->user_login !== 'USERNAME') {
      add_filter('user_can_richedit', create_function('','return false;'),50);}}
add_action('init','disable_visual_editor');
?>

What I am doing here is, simply checking if the current user has your "USERNAME" or not. If the current user doesn't have your username, this function will disable the "Visual" mode. In other words, everyone but the username mentioned on this snippet will loose their visual editing capability. Also don't forget to change "USERNAME" with your actual username.

Disable for Everyone but Administrators

You may ask, what about if I have multiple site "administrator" and you want none but only the admin to have "Visual" editing capability? Well, here is your answer.

<?php
function disable_visual_editor(){
   if (!current_user_can('manage_options')){
      add_filter('user_can_richedit', create_function('','return false;'),50);}}
add_action('init','disable_visual_editor');
?>

This is also pretty simple idea. I am just checking if the user has "manage_options" capability or not. Since only site admin has such capability, any non-admin user would loose the visual editing capability. Hope that helps.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.