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

前端 未结 3 1517
旧时难觅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:06

    Another way if you use custom post type.

    When you register a cpt add add_post_type_support( 'news', 'excerpt' );

    Full example :

    function create_news() {
        $args = [
            'labels' => [
                'name' => __( 'News', 'lang' ),
                'singular_name' => __( 'News', 'lang' ),
                'add_new_item'       => __( 'Add a news', 'lang' ),
        ],
            'public' => true,
            'has_archive' => true,
            'menu_icon' => 'dashicons-admin-post',
            'show_in_rest' => false,
            'rewrite' => ['slug' => 'news'],
            'show_in_nav_menus' => true,
        ];
    
        register_post_type( 'news',
            $args
        );
    }
    add_action( 'init', 'create_news' );
    add_post_type_support( 'news', 'excerpt' );
    

提交回复
热议问题