本文档指导如何在不同版本的 theme.json 之间进行迁移,包括从 v1 升级到 v2 和从 v2 升级到 v3。升级可启用新功能并确保一致性,旧版本仍受支持但建议升级以获取最新开发。
// 从 v1 迁移到 v2 示例
{
"version": 2,
"settings": {
"border": {
"radius": "10px" // 原为 customRadius
},
"spacing": {
"margin": "20px" // 原为 customMargin
}
}
}
// 从 v2 迁移到 v3 示例
{
"version": 3,
"settings": {
"typography": {
"defaultFontSizes": false // 控制默认字体大小显示
},
"spacing": {
"defaultSpacingSizes": false // 控制默认间距大小显示
}
}
}This guide documents the changes between different theme.json versions and how to upgrade. Using older versions will continue to be supported. Upgrading is recommended because new development will continue in the newer versions.
Upgrading to v2 enables some new features and adjusts the naming of some old features to be more consistent with one another.
version to 2.Refer to the dev note for the release and the reference documents for the respective v1 and v2 versions.
| v1 | v2 |
|---|---|
settings.border.customRadius |
settings.border.radius |
settings.spacing.customMargin |
settings.spacing.margin |
settings.spacing.customPadding |
settings.spacing.padding |
settings.typography.customLineHeight |
settings.typography.lineHeight |
New top-level properties: customTemplates, templateParts.
Additions to settings:
settings.appearanceToolssettings.border.colorsettings.border.stylesettings.border.widthsettings.color.backgroundsettings.color.defaultGradientssettings.color.defaultPalettesettings.color.textsettings.spacing.blockGapsettings.typography.fontFamiliessettings.typography.fontStylesettings.typography.fontWeightsettings.typography.letterSpacingsettings.typography.textColumnssettings.typography.textDecorationsettings.typography.textTransformAdditions to styles:
styles.border.colorstyles.border.stylestyles.border.widthstyles.filter.duotonestyles.spacing.blockGapstyles.typography.fontFamilystyles.typography.fontStylestyles.typography.fontWeightstyles.typography.letterSpacingstyles.typography.textColumnsstyles.typography.textDecorationstyles.typography.textTransformThe default font sizes provided by core (settings.typography.fontSizes) have been updated. The Normal and Huge sizes (with normal and huge slugs) have been removed from the list, and Extra Large (x-large slug) has been added. When the UI controls show the default values provided by core, Normal and Huge will no longer be present. However, their CSS classes and CSS Custom Properties are still enqueued to make sure existing content that uses them still works as expected.
Upgrading to v3 adjusts preset defaults to be more consistent with one another.
version to 3.settings.typography.defaultFontSizesIn theme.json v2, the default font sizes were only shown when theme sizes were not defined. A theme providing font sizes with the same slugs as the defaults would always override them.
The default fontSizes slugs are: small, medium, large, x-large, and xx-large.
The new defaultFontSizes option gives control over showing default font sizes and preventing those defaults from being overridden.
true it will show the default font sizes and prevent them from being overridden by the theme.false it will hide the default font sizes and allow the theme to use the default slugs.It is true by default when switching to v3. This is to be consistent with how other default* options work such as settings.color.defaultPalette, but differs from the behavior in v2.
To keep behavior similar to v2 with a v3 theme.json:
* If you do not have any fontSizes defined, defaultFontSizes can be left out or set to true.
* If you have some fontSizes defined, set defaultFontSizes to false.
settings.spacing.defaultSpacingSizesIn theme.json v2, there are two settings that could be used to set theme level spacing sizes: settings.spacing.spacingSizes and settings.spacing.spacingScale. Setting both spacingSizes and spacingScale would only use the values from spacingSizes. And setting either of them would always replace the entire set of default spacing sizes provided by WordPress.
The default spacingSizes slugs provided by WordPress are: 20, 30, 40, 50, 60, 70, and 80.
The new defaultSpacingSizes option gives control over showing default spacing sizes and preventing those defaults from being overridden.
true it will show the default spacing sizes and prevent them from being overridden by the theme.false it will hide the default spacing sizes and allow the theme to use the default slugs.defaultSpacingSizes is true by default when switching to v3. This is to be consistent with how other default* options work such as settings.color.defaultPalette, but differs from the behavior in v2.
Additionally, in v3 both spacingSizes and spacingScale can be set at the same time. Presets defined in spacingSizes with slugs matching the generated presets from spacingSizes will override the generated ones.
To keep behavior similar to v2 with a v3 theme.json:
* If you do not have any spacingSizes presets or spacingScale config defined, defaultSpacingSizes can be left out or set to true.
* If you disabled default spacing sizes by setting spacingScale to { "steps": 0 }, remove the spacingScale config and set defaultSpacingSizes to false.
* If you defined only one of either spacingScale or spacingSizes for your presets, set defaultSpacingSizes to false.
* If you defined both spacingScale and spacingSizes, remove the spacingSizes config and set defaultSpacingSizes to false.