Gutenberg 区块编辑器文档

title: "Theme.json 版本 2 参考文档" post_status: publish comment_status: open taxonomy: category: - gutenberg-docs post_tag: - Theme Json Reference - Reference Guides - Repos


Theme.json 版本 2 参考文档

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

Theme.json 版本 3 已随 WordPress 6.6 发布。WordPress 将继续支持 theme.json 版本 2。但新功能将仅添加到[新版本](/docs/reference-guides/theme-json-reference/theme-json-living)。 当您准备升级时,请参阅 [theme.json 迁移指南](/docs/reference-guides/theme-json-reference/theme-json-migrations#migrating-from-v2-to-v3) 了解更新到最新版本的详细信息。

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

JSON 模式

本文档由 theme.json 的 JSON 模式生成。

版本 2 的最新模式位于 https://schemas.wp.org/wp/6.5/theme.json

每个 WordPress 版本的 theme.json 模式均可在 https://schemas.wp.org/wp/{{version}}/theme.json 获取。例如,WordPress 5.9 的模式位于 https://schemas.wp.org/wp/5.9/theme.json

关于如何在编辑器中应用此 JSON 模式,请参阅使用 theme.json 进行开发

设置

appearanceTools

启用以下 UI 工具的设置:


useRootPaddingAwareAlignments

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

请注意,使用此设置时,styles.spacing.padding 应始终设置为一个对象,并分别声明 toprightbottomleft 值。


边框

与边框相关的设置。

属性 类型 默认值 属性参数
color boolean false
radius boolean false
style boolean false
width boolean false

阴影

与阴影相关的设置。

属性 类型 默认值 参数
defaultPresets boolean true
presets array name, shadow, slug

color

Settings related to colors.

Property Type Default Props
background boolean true
custom boolean true
customDuotone boolean true
customGradient boolean true
defaultDuotone boolean true
defaultGradients boolean true
defaultPalette boolean true
duotone array colors, name, slug
gradients array gradient, name, slug
link boolean false
palette array color, name, slug
text boolean true
heading boolean true
button boolean true

背景

与背景相关的设置。

属性 类型 默认值 Props
backgroundImage boolean false

尺寸

与尺寸相关的设置。

属性 类型 默认值 Props
aspectRatio boolean false
minHeight boolean false

布局

与布局相关的设置。

属性 类型 默认值 属性
contentSize string
wideSize string
allowEditing boolean true
allowCustomContentAndWideSize boolean true

与灯箱相关的设置。

属性 类型 默认值 Props
enabled boolean
allowEditing boolean

spacing

Settings related to spacing.

Property Type Default Props
blockGap boolean, null null
margin boolean false
padding boolean false
units array px,em,rem,vh,vw,%
customSpacingSize boolean true
spacingSizes array name, size, slug
spacingScale object

typography

Settings related to typography.

Property Type Default Props
customFontSize boolean true
fontStyle boolean true
fontWeight boolean true
fluid object, boolean false {maxViewportWidth, minFontSize, minViewportWidth}
letterSpacing boolean true
lineHeight boolean false
textColumns boolean false
textDecoration boolean true
writingMode boolean false
textTransform boolean true
dropCap boolean true
fontSizes array fluid, name, size, slug
fontFamilies array fontFace, fontFamily, name, slug

custom

生成形式为 --wp--custom--{key}--{nested-key}: {value}; 的自定义 CSS 自定义属性。camelCased 格式的键名会转换为 kebab-case 以遵循 CSS 属性命名规范。不同深度的键名之间用 -- 分隔,因此键名中不应包含 --

Styles

border

Border styles.

Property Type Props
color string, object
radius string, object
style string, object
width string, object
top object color, style, width
right object color, style, width
bottom object color, style, width
left object color, style, width

颜色

颜色样式。

属性 类型 属性参数
background string, object
gradient string, object
text string, object

间距

间距样式。

属性 类型 参数
blockGap string, object
margin object bottom, left, right, top
padding object bottom, left, right, top

typography

Typography styles.

Property Type Props
fontFamily string, object
fontSize string, object
fontStyle string, object
fontWeight string, object
letterSpacing string, object
lineHeight string, object
textColumns string
textDecoration string, object
writingMode string, object
textTransform string, object

filter

CSS 和 SVG 滤镜样式。

属性 类型 参数
duotone string, object

轮廓

轮廓样式。

属性 类型 参数
color string, object
offset string, object
style string, object
width string, object

css

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


customTemplates

为 templates 文件夹中定义的自定义模板提供额外元数据。

类型:object

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

templateParts

parts 文件夹中定义的模板部件的附加元数据。

类型:object

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

模式

一组将从模式目录中注册的模式 slug。 类型:array