简体   繁体   English

限制Gutenberg Editor的自定义帖子类型wordpress

[英]Restrict Gutenberg Editor for custom post type wordpress

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. 我需要创建自己的自定义帖子类型,并希望将Gutenberg编辑器限制为我的帖子类型(仅),并在此帖子类型中使用WordPress编辑器。 how can limit this plugin for my cpt?? 如何才能为我的cpt限制此插件?

thanks 谢谢

You can use filter to disable Gutenberg for all post type with the exception of you custom post type name. 您可以使用过滤器为所有帖子类型禁用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 );

You can do this by plugin or custom code. 您可以通过插件或自定义代码来执行此操作。

  1. Plugin Disable Gutenberg 禁用古腾堡插件

  2. Code, add it to functions.php 代码,将其添加到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); 

For those finding this question after WordPress 5.0 was released, you can turn off the Block Editor (fka Gutenberg) for certain post types by using the use_block_editor_for_post_type filter like so: 对于那些在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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM