Remove the editor on specific pages in WordPress

This tutorial is aimed people, using WordPress classic. I.e. Users using non Gutenberg sites.

Using WordPress, on occasion you might want to add content to your pages exclusively without the need for the content editor.

One example is if you are using a custom template that heavily relies on many custom fields such as an intro, slider, call to action, latest news, tweets etc etc and just have no use for the editor to be there. Maybe this template is relying upon the use of flexible content fields so that a client can easily update a page themselves and by still including the default editor in the page the client might get confused as to why it’s there.

So hopefully we’ve agreed that it’s more user friendly to omit the editor for this type of scenario.

Let’s create a function to remove the editor

So first things first – let’s open up our functions.php file and create our custom function.

function feh_remove_editor() 
{
}

Next we are going to test whether the post variable exists in the URL to see if we are on a post, page, CPT etc in the backend.

function feh_remove_editor()
{
   if (isset($_GET['post'])) 
   { 
			
   }
}

Next up, we want to get the current post ID, and set up an array to hold the IDs of posts we want the editor excluded from.

function feh_remove_editor()
{
   if (isset($_GET['post']))
   {
      $id = $_GET['post'];

      $remove_editor_ids = array(6);
   }
}
add_action('init', 'feh_remove_editor');

Now, we are going to loop through our $remove_editor_ids array and check if the current post ID is in this array with the help of PHP’s in_array function. If a match is found, we will use the remove_post_type_support to simply remove the editor for this post ID.

The final bit is just hooking up our function to the init hook.

The full solution

function feh_remove_editor() 
{
   if (isset($_GET['post'])) 
   {	
      $id = $_GET['post'];
			
      $remove_editor_ids = array(6);
			
      foreach($remove_editor_ids as $remove_editor_id) 
      {
         if (in_array($id, $remove_editor_ids)) 
         {
            remove_post_type_support('page', 'editor');
         }
      }
   }
}
add_action('init', 'feh_remove_editor');

Remove editor from other posts types

To remove the editor from pages or custom post types, just add a new snippet:

remove_post_type_support('page', 'editor');
remove_post_type_support('event', 'editor');

You can reply to this post by tweeting to me