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

时间:2018-10-17 08:02:30

标签: wordpress wordpress-gutenberg

我需要创建自己的自定义帖子类型,并希望将Gutenberg编辑器限制为我的帖子类型(仅),并在此帖子类型中使用WordPress编辑器。 如何才能为我的cpt限制此插件?

谢谢

3 个答案:

答案 0 :(得分:2)

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

/**
 * 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 );

答案 1 :(得分:1)

您可以通过插件或自定义代码来完成此操作。

  1. 插件Disable Gutenberg

  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);

答案 2 :(得分:1)

对于那些在WordPress 5.0发布后发现此问题的人,您可以使用 use_block_editor_for_post_type 过滤器来关闭某些帖子类型的“块编辑器”(f.k.a 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);
相关问题