这是 theme.json 的版本 2规范。此版本适用于 WordPress 5.9 或更高版本。

随着 WordPress 6.6 的发布,theme.json 版本 3 也已推出。WordPress 将继续支持 theme.json 版本 2。然而,新功能将仅添加到[新版本](https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/)中。

当您准备升级时,请参阅 [theme.json 迁移指南](https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-migrations/#migrating-from-v2-to-v3),了解更新到最新版本的相关信息。

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

JSON Schema

本文档是根据 theme.json 的 JSON schema 生成的。

版本 2 的最新 schema 可在 `https://schemas.wp.org/wp/6.5/theme.json` 获取。

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

请参阅 使用 theme.json 进行开发,了解如何在编辑器中使用 JSON schema。

设置

appearanceTools

启用以下 UI 工具的设置:

  • background: backgroundImage, backgroundSize
  • border: color, radius, style, width
  • color: link
  • dimensions: aspectRatio, minHeight
  • position: sticky
  • spacing: blockGap, margin, padding
  • typography: lineHeight

useRootPaddingAwareAlignments

启用根内边距(来自 styles.spacing.padding 的值)应用于全宽块的内容,而不是根块。

请注意,使用此设置时,styles.spacing.padding 应始终设置为对象,并分别声明 top、right、bottom、left 值。


border

与边框相关的设置。

属性类型默认值Props
colorbooleanfalse
radiusbooleanfalse
stylebooleanfalse
widthbooleanfalse

shadow

与阴影相关的设置。

属性类型默认值Props
defaultPresetsbooleantrue
presetsarrayname, shadow, slug

color

与颜色相关的设置。

属性类型默认值Props
backgroundbooleantrue
custombooleantrue
customDuotonebooleantrue
customGradientbooleantrue
defaultDuotonebooleantrue
defaultGradientsbooleantrue
defaultPalettebooleantrue
duotonearraycolors, name, slug
gradientsarraygradient, name, slug
linkbooleanfalse
palettearraycolor, name, slug
textbooleantrue
headingbooleantrue
buttonbooleantrue

background

与背景相关的设置。

属性类型默认值Props
backgroundImagebooleanfalse

dimensions

与尺寸相关的设置。

属性类型默认值Props
aspectRatiobooleanfalse
minHeightbooleanfalse

layout

与布局相关的设置。

属性类型默认值Props
contentSizestring
wideSizestring
allowEditingbooleantrue
allowCustomContentAndWideSizebooleantrue

lightbox

与灯箱相关的设置。

属性类型默认值Props
enabledboolean
allowEditingboolean

position

与位置相关的设置。

属性类型默认值Props
stickybooleanfalse

spacing

与间距相关的设置。

属性类型默认值Props
blockGapboolean, nullnull
marginbooleanfalse
paddingbooleanfalse
unitsarraypx,em,rem,vh,vw,%
customSpacingSizebooleantrue
spacingSizesarrayname, size, slug
spacingScaleobject

typography

与排版相关的设置。

属性类型默认值Props
customFontSizebooleantrue
fontStylebooleantrue
fontWeightbooleantrue
fluidobject, booleanfalse{maxViewportWidth, minFontSize, minViewportWidth}
letterSpacingbooleantrue
lineHeightbooleanfalse
textColumnsbooleanfalse
textDecorationbooleantrue
writingModebooleanfalse
textTransformbooleantrue
dropCapbooleantrue
fontSizesarrayfluid, name, size, slug
fontFamiliesarrayfontFace, fontFamily, name, slug

custom

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


样式

border

边框样式。

属性类型Props
colorstring, object
radiusstring, object
stylestring, object
widthstring, object
topobjectcolor, style, width
rightobjectcolor, style, width
bottomobjectcolor, style, width
leftobjectcolor, style, width

color

颜色样式。

属性类型Props
backgroundstring, object
gradientstring, object
textstring, object

dimensions

尺寸样式

属性类型Props
aspectRatiostring, object
minHeightstring, object

spacing

间距样式。

属性类型Props
blockGapstring, object
marginobjectbottom, left, right, top
paddingobjectbottom, left, right, top

typography

排版样式。

属性类型Props
fontFamilystring, object
fontSizestring, object
fontStylestring, object
fontWeightstring, object
letterSpacingstring, object
lineHeightstring, object
textColumnsstring
textDecorationstring, object
writingModestring, object
textTransformstring, object

filter

CSS 和 SVG 滤镜样式。

属性类型Props
duotonestring, object

shadow

盒阴影样式。


outline

轮廓样式。

属性类型Props
colorstring, object
offsetstring, object
stylestring, object
widthstring, object

css

设置自定义 CSS,以应用其他 theme.json 属性未涵盖的样式。


customTemplates

在 templates 文件夹中定义自定义模板的其他元数据。

类型:object。

属性描述类型
nametemplates 文件夹中模板的文件名(不含扩展名)。string
title模板标题,可翻译。string
postTypes可使用此自定义模板的文章类型列表。array

templateParts

在 parts 文件夹中定义的模板部件的其他元数据。

类型:object。

属性描述类型
nameparts 文件夹中模板部件的文件名(不含扩展名)。string
title模板部件标题,可翻译。string
area该模板部件使用的区域。存在用于 header 和 footer 值的区块变体,当区域设置为其中之一时将使用这些变体。string

Patterns

要从 Pattern Directory 注册的图案 slug 数组。
类型:array。