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

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

    as the other users shown above it is possible yes. Also, i'd like to make the following known.

    In the latest Wordpress or Wordpress 5+ - (With Gutenberg) The 2 methods have the same effect to removing Gutenberg but also have different options when doing so:

    (Insert both to functions.php or custom plugin functions)

    To remove Gutenberg from your post type:

    add_filter('use_block_editor_for_post_type', 'prefix_disable_gutenberg', 10, 2);
    
     function prefix_disable_gutenberg($gutenberg_filter, $post_type)
      {
       if ($post_type === 'your_post_type') return false;
       return $gutenberg_filter;
      }
    

    The above will remove Gutenberg editor completely from your custom post type but also leave other meta boxes/etc available and untouched.

    However, if you wish to remove the text editor/text area itself - or other default options WordPress also considers this as Gutenberg, so you can remove this specifically and remove Gutenberg at the same time by adding the following:

    add_action('init', 'init_remove_editor',100);
    
     function init_remove_editor(){
      $post_type = 'your_post_type';
      remove_post_type_support( $post_type, 'editor');
     }
    

    The above will disable Gutenberg & the 'editor' of wordpress. This can replaced with other metabox/data options. (Author / Thumbnail /Revisions etc)

提交回复
热议问题