Remove Editor From Homepage

There are a couple of issues with your approach

By using the admin_init hook you won’t have any reference to the post object. This means you won’t be able to get the post ID or use anything like get_the_ID because the post won’t actually be loaded. You can see that in the order here https://codex.wordpress.org/Plugin_API/Action_Reference

So if you run the action hook after the wp action you’ll have the post object. For example

add_action('admin_head', 'remove_content_editor');
/**
 * Remove the content editor from ALL pages 
 */
function remove_content_editor()
{ 
    remove_post_type_support('page', 'editor');        
}

Now this snippet will remove the editor from all pages. The problem is that is_home and is_front_page won’t work on the admin side so you’ll need to add some meta data to distinguish whether you’re on the home page. There’s a very comprehensive discussion of approaches for that on this page: Best way to present options for home page in admin?

So, if you used some extra meta data, you can then check this like

add_action('admin_head', 'remove_content_editor');
/**
 * Remove the content editor from ALL pages 
 */
function remove_content_editor()
{
    //Check against your meta data here
    if(get_post_meta( get_the_ID(), 'is_home_page' )){      
        remove_post_type_support('page', 'editor');         
    }

}

Hopefully that will help you out

******* Update ************

Actually, I’ve just looked into this again and realised that there is an easier way. If you have set the front page to be a static page in the Reading settings, you can check against the page_on_front option value. In that case, the following will work

add_action('admin_head', 'remove_content_editor');
/**
 * Remove the content editor from pages as all content is handled through Panels
 */
function remove_content_editor()
{
    if((int) get_option('page_on_front')==get_the_ID())
    {
        remove_post_type_support('page', 'editor');
    }
}

Leave a Comment