WordPress自定义文章类型register_post_type 调用古登堡编辑器
七娃博客270人阅读
WordPress通过 register_post_type函数 自定义文章类型如何调用古登堡编辑器呐?今天突然发现之前自定义的专题分类的编辑器不是古登堡。用惯了新编辑器,看到默认的编辑器,有种这样的感觉:经常开车的人,突然让我蹬自行车!这谁受得了,搞他!
如何自定义文章类型,可以参考这篇文章: 《wordpress自定义“专题”分类及页面并调用数据(wordpress 自定义文章类型)》
之前注册自定义文章类型的是通过register_post_type函数实现的,还得从这个函数入手:
register_post_type( 'series', //新增文章类型,series为名称 array( 'labels' => array( 'name' => '专题', 'singular_name' => '所有专题', 'add_new' => '添加专题', 'add_new_item' => '添加新专题', 'edit' => '编辑', 'edit_item' => '编辑专题', 'new_item' => '新专题', 'view' => '查看专题', 'view_item' => '查看专题', 'search_items' => '搜索专题', 'not_found' => '没有找到相关专题', 'not_found_in_trash' => '没有专题评论', 'parent' => '专题评论', ), 'exclude_from_search'=>false, 'public' => true, 'menu_position' => 6, 'supports' => array( 'title', 'editor','comments', 'custom-fields','thumbnail','excerpt'), //为自定义文章添加标题,编辑器,评论,自定义字段,特色图像,摘要功能 'taxonomies' => array( '' ), //分类法,我们是单独定义 'has_archive' => true, // 'taxonomies'=> array('post_tag'), //没有这一句是没有标签功能的 ) );
然后通过度娘之后,发现需要加一个这样的参数: 'show_in_rest' => true 。这样刷新就可以调起来wp自带的古登堡编辑器了。完整代码如下:
register_post_type( 'series', //新增文章类型,series为名称 array( 'labels' => array( 'name' => '专题', 'singular_name' => '所有专题', 'add_new' => '添加专题', 'add_new_item' => '添加新专题', 'edit' => '编辑', 'edit_item' => '编辑专题', 'new_item' => '新专题', 'view' => '查看专题', 'view_item' => '查看专题', 'search_items' => '搜索专题', 'not_found' => '没有找到相关专题', 'not_found_in_trash' => '没有专题评论', 'parent' => '专题评论', ), 'exclude_from_search'=>false, 'public' => true, 'menu_position' => 6, 'supports' => array( 'title', 'editor','comments', 'custom-fields','thumbnail','excerpt'), //为自定义文章添加标题,编辑器,评论,自定义字段,特色图像,摘要功能 'show_in_rest' => true,//调用古登堡编辑器 'taxonomies' => array( '' ), //分类法,我们是单独定义 'has_archive' => true, // 'taxonomies'=> array('post_tag'), //没有这一句是没有标签功能的 ) );
以上就是WordPress自定义文章类型register_post_type 调用古登堡编辑器的全部内容了
评论 | 0 条评论
登录之后才可留言,前往登录