1

I need to create my own custom post type and want to limit Gutenberg editor for my post type(only) and use WordPress editor in this post type. how can limit this plugin for my cpt??

thanks

4

3 回答 3

2

您可以使用过滤器为所有帖子类型禁用 Gutenberg,但自定义帖子类型名称除外。

/**
 * Disabling the Gutenberg editor all post types except post.
 *
 * @param bool   $can_edit  Whether to use the Gutenberg editor.
 * @param string $post_type Name of WordPress post type.
 * @return bool  $can_edit
 */
function gutenberg_can_edit_post_type_83744857( $can_edit, $post_type ) {
    $gutenberg_supported_types = array( 'post' ); //Change this to you custom post type
    if ( ! in_array( $post_type, $gutenberg_supported_types, true ) ) {
        $can_edit = false;
    }
    return $can_edit;
}
add_filter( 'gutenberg_can_edit_post_type', 'gutenberg_can_edit_post_type_83744857', 10, 2 );
于 2018-10-17T08:44:13.040 回答
1

对于那些在 WordPress 5.0 发布后发现这个问题的人,您可以使用use_block_editor_for_post_type过滤器来关闭某些帖子类型的块编辑器(fka Gutenberg),如下所示:

add_filter('use_block_editor_for_post_type', function( $useBlockEditor, $postType ){

    if( $postType == 'your-custom-post-type-slug' )
        return false;
    return $useBlockEditor;

}, 10, 2);
于 2019-01-15T16:41:26.927 回答
1

您可以通过插件或自定义代码来做到这一点。

  1. 插件禁用古腾堡

  2. 代码,添加到functions.php

function mh_disable_gutenberg($is_enabled, $post_type) {

  if ($post_type === 'news') return false; // change news to your post type

  return $is_enabled;

}
add_filter('gutenberg_can_edit_post_type', 'mh_disable_gutenberg', 10, 2);
于 2018-10-17T08:59:06.307 回答