skip to Main Content

I am creating a new WordPress Theme and would like to use the Classic Editor specifically on the front page. To achieve this, I plan to modify the functions.php file with a few lines of code instead of relying on a plugin.

I would like to maintain the Gutenberg editor for other pages and posts.

Despite trying different methods, I have not found a solution that worked. Or I am able to remove the Gutenberg Editor from all the pages, or not remove it at all.

That’s my most recent try.

Does someone know what can I do?

Thanks a lot!!!

function use_classic_editor_on_front_page( $use_block_editor, $post_type ) {
    if ( ! is_admin() && is_front_page() && 'page' === $post_type ) {
        return false;
    }
    return $use_block_editor;
}
add_filter( 'use_block_editor_for_post_type', 'use_classic_editor_on_front_page', 10, 2 );

2

Answers


  1. Chosen as BEST ANSWER

    Eventually, (and thanks to the direction Asiqur gave me) I found another solution that goes even more in detail, removing the block editor from a specific page, in this case, the one with the title "Home". Decided to share it here.

    add_filter('use_block_editor_for_post_type', 'use_classic_editor_on_page_name', 10, 2);
    function use_classic_editor_on_page_name($use_block_editor, $post_type)
    {
        if ($post_type === 'page' && get_the_title() == 'Home') {
            $use_block_editor = false;
            remove_post_type_support('page', 'editor');
        } else if ($post_type === 'page' && get_the_title() !== 'Home') {
            $use_block_editor = true;
        } else if ($post_type === 'post') {
            $use_block_editor = true;
        }
    
        return $use_block_editor;
    }
    

  2. hope this helps,

    add_filter( 'use_block_editor_for_post_type', 'use_classic_editor_on_front_page' );
    function use_classic_editor_on_front_page( $use_block_editor ) {
        if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && get_the_ID() == get_option( 'page_on_front' ) ) {
            $use_block_editor = false;
        }
        
        return $use_block_editor;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search