这是 version 1 的 theme.json 规范。此版本适用于 WordPress 5.8 或更高版本。

Theme.json version 2 已随 WordPress 5.9 发布。WordPress 将继续支持 theme.json version 1。但是,新功能将仅添加到 [new versions](https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/) 中。

当您准备升级时,请参阅 [theme.json migration guide](https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-migrations/#migrating-from-v1-to-v2) 以获取升级到最新版本的详细信息。

本参考指南列出了在 theme.json schema 中定义的设置和样式属性。有关如何在主题中使用 theme.json 文件的示例和指导,请参阅 theme.json how to guide。

JSON Schema

Version 1 的最新 schema 可在 `https://schemas.wp.org/wp/5.8/theme.json` 获取。

每个 WordPress 版本的 Theme.json schemas 可在 https://schemas.wp.org/wp/{{version}}/theme.json` 获取。例如,WordPress 5.8 的 schema 可在https://schemas.wp.org/wp/5.8/theme.json` 获取。

有关如何在编辑器中使用 JSON schema,请参阅 Developing with theme.json。

Settings

border

与边框相关的设置。

PropertyTypeDefaultProps
customRadiusbooleanfalse

color

与颜色相关的设置。

PropertyTypeDefaultProps
custombooleantrue
customDuotonebooleantrue
customGradientbooleantrue
duotonearraycolors, name, slug
gradientsarraygradient, name, slug
linkbooleanfalse
palettearraycolor, name, slug

layout

与布局相关的设置。

PropertyTypeDefaultProps
contentSizestring
wideSizestring

spacing

与间距相关的设置。

PropertyTypeDefaultProps
customMarginbooleanfalse
customPaddingbooleanfalse
unitsarraypx,em,rem,vh,vw,%

typography

与排版相关的设置。

PropertyTypeDefaultProps
customFontSizebooleantrue
customLineHeightbooleanfalse
dropCapbooleantrue
fontSizesarrayname, size, slug

custom

生成形式为 --wp--custom--{key}--{nested-key}: {value}; 的自定义 CSS custom properties。遵循 CSS 属性命名 schema,camelCased 键将转换为 kebab-case。不同深度级别的键由 -- 分隔,因此键名中不应包含 --。


Styles

border

边框样式。

PropertyTypeProps
radiusstring

color

颜色样式。

PropertyTypeProps
backgroundstring
gradientstring
textstring

spacing

间距样式。

PropertyTypeProps
marginobjectbottom, left, right, top
paddingobjectbottom, left, right, top

typography

排版样式。

PropertyTypeProps
fontSizestring
lineHeightstring