块编辑器开发文档

💡 云策文档标注

概述

本文档介绍了 WordPress 主题与区块编辑器的交互方式,包括经典主题和区块主题的定义、区别及其配置选项。重点强调了 theme.json 文件在提供全局设置和样式控制中的作用。

关键要点

  • 区块编辑器为主题设计者和开发者提供多种交互选项,如主题定义的颜色设置和字体大小控制。
  • 经典主题使用传统的 .php 文件格式定义模板,可通过 Theme Supports 或 theme.json 文件配置区块编辑器。
  • 区块主题至少包含 /block-templates 或 /templates 文件夹中的 index.html 模板,允许使用区块编辑器编辑整个站点。
  • WordPress 5.9 及以上版本中,任何区块主题都支持全站编辑(FSE)。
  • theme.json 文件用于定义全局设置和样式,但并非区块主题的必需项。

📄 原文内容

The block editor provides a number of options for theme designers and developers, to interact with it, including theme-defined color settings, font size control, and much more.

Types of themes

Classic theme

In terms of block editor terminology this is any theme that defines its templates in the traditional .php file format, and that doesn’t have an index.html format template in the /block-templates or /templates folders. A Classic theme has the ability to provide configuration and styling options to the block editor, and block content, via Theme Supports, or by including a theme.json file. A theme does not have to be a Block theme in order to take advantage of some of the flexibility provided by the use of a theme.json file.

Block theme

This is any theme that has, at a minimum, an index.html format template in the /block-templates or /templates folders, and with templates provided in form of block content markup. While many Block themes will make use of a theme.json file to provide configuration and styling settings, a theme.json is not a requirement of Block themes. The advantage of Block themes is that the block editor can be used to edit all areas of the site: headers, footers, sidebars, etc.

Full site editing (FSE)

There isn’t an FSE specific theme type. In WordPress > 5.9 FSE is enabled for any Block theme, ie. any theme that has an index.html format template in the /block-templates or /templates folders.

Contents