You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为WordPress自定义文章类型启用Gutenberg编辑器?

为自定义文章类型启用Gutenberg编辑器

你的代码里存在无效参数,同时需确认几个核心配置,以下是具体修正方案:

  1. 删除无效参数
    你代码里的'guttenberg' => true是拼写错误且无意义的参数,直接删除这一行即可。

  2. 确认核心启用条件
    启用Gutenberg有两个必要条件,你的代码里已包含,但需确保未被其他代码覆盖:

  • 'show_in_rest' => true:Gutenberg依赖REST API运行,这个参数用于开启自定义文章类型的REST API支持
  • supports数组包含'editor':确保编辑器功能被启用
  1. 修正后的完整代码
$restaurants_args = array(
    'labels' => array(
        'name' => '餐厅',
        'singular_name' => '餐厅',
        'all_items' => '所有餐厅',
        'add_new' => '添加新餐厅',
        'add_new_item' => '添加新餐厅',
        'edit_item' => '编辑餐厅',
        'new_item' => '新餐厅',
        'view_item' => '查看餐厅',
        'search_items' => '搜索餐厅',
        'not_found' => '未找到餐厅',
        'not_found_in_trash' => '回收站中没有餐厅',
        'parent_item_colon' => ''
    ),
    'public' => true,
    'public_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => 5,
    'show_in_rest' => true,
    'supports' => array(
        'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields', 'post-formats'
    ),
    'has_archive' => true
);
// 注册自定义文章类型
register_post_type('restaurants', $restaurants_args);

如果修正后仍无法启用Gutenberg,可排查以下情况:

  • 检查是否安装了Classic Editor插件,若有,需在插件设置中允许该自定义文章类型使用块编辑器,或直接禁用插件
  • 确保WordPress版本在5.0及以上,Gutenberg从该版本开始内置
  • 检查主题是否通过use_block_editor_for_post_type过滤器禁用了该自定义文章类型的块编辑器,若有则调整对应代码

内容的提问来源于stack exchange,提问作者sadasdadssad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 08:17:16