How to disable Gutenberg / block editor for certain post types?

前端 未结 3 1515
旧时难觅i
旧时难觅i 2021-02-01 10:40

WordPress added Gutenberg / block editor in its 5th version and it\'s enabled by default for Post and Page post types.

It might be enabled by default fo

3条回答
  •  孤独总比滥情好
    2021-02-01 11:07

    It's possible to simply disable the editor using a WordPress filter.

    WordPress 5 and Higher

    If you want to disable the block editor only for your own post types, you can add following code into your plugin or functions.php file of your theme.

    add_filter('use_block_editor_for_post_type', 'prefix_disable_gutenberg', 10, 2);
    function prefix_disable_gutenberg($current_status, $post_type)
    {
        // Use your post type key instead of 'product'
        if ($post_type === 'product') return false;
        return $current_status;
    }
    

    If you want to disable the block editor completely (Not recommended), you can use following code.

    add_filter('use_block_editor_for_post_type', '__return_false');
    

    Gutenberg Plugin (Before WordPress 5)

    If you want to disable the Gutenberg editor only for your own post types, you can add following code into your plugin or functions.php file of your theme.

    add_filter('gutenberg_can_edit_post_type', 'prefix_disable_gutenberg', 10, 2);
    function prefix_disable_gutenberg($current_status, $post_type)
    {
        // Use your post type key instead of 'product'
        if ($post_type === 'product') return false;
        return $current_status;
    }
    

    If you want to disable the Gutenberg editor completely (Not recommended), you can use following code.

    add_filter('gutenberg_can_edit_post_type', '__return_false');
    

提交回复
热议问题