在定义自定义帖子类型的代码中(在自定义插件或functions.php
文件),您需要添加此代码段以支持Gutenberg块编辑器:
\'show_in_rest\' => true,
\'supports\' => array(\'editor\')
以下是一个示例:
function portfolio_post_type() {
register_post_type( \'portfolio\',
array(
\'labels\' => array(
\'name\' => __( \'Portfolio\' ),
\'singular_name\' => __( \'Portfolio\' )
),
\'has_archive\' => true,
\'public\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'),
\'show_in_rest\' => true,
\'supports\' => array(\'editor\')
)
);
}
add_action( \'init\', \'portfolio_post_type\' );