当前位置:蚂蚁分类目录 » 站长资讯 » 站长运营 » WordPress教程 » 文章详细 订阅RssFeed

如何让WordPress自定义文章类型支持Gutenberg古腾堡编辑器?WordPress教程

来源:博客吧 浏览:1492次 时间:2021-05-19 20:15:20

WordPress 5.0版本之后启用Gutenberg古腾堡编辑器作为默认文章编辑器,但是发现创建的自定义文章类型在添加文章时,使用的还是TinyMCE编辑器,查找资料后发现,要让自定义文章类型支持古腾堡编辑器,还需要在register_post_type中添加show_in_rest参数,据了解是大致是因为Gutenberg编辑器必须利用REST API进行更新和更改,总之问题是解决了。

代码如下:

1
2
3
4
5
6
7
8
9
10
$args = array( 
'labels' => $labels,
 'description' => '产品列表',
 'public' => true,
 'menu_position' => 5,
 'supports' => array('title','editor','thumbnail'), //supports中需要有editor  
'show_in_rest' => true,//增加的参数
 'has_archive' => true ); 
register_post_type( 'product_type', $args );

WordPress官网对参数的说明:

‘show_in_rest’
(bool) Whether to include the post type in the REST API. Set this to true for the post type to be available in the block editor.