You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to-guides/themes/theme-json.md
+98-22Lines changed: 98 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,10 @@ WordPress 5.8 comes with [a new mechanism](https://make.wordpress.org/core/2021/
10
10
- Specification
11
11
- version
12
12
- settings
13
+
- Backward compatibility with add_theme_support
13
14
- Presets
14
15
- Custom
16
+
- Setting examples
15
17
- styles
16
18
- Top-level
17
19
- Block-level
@@ -269,6 +271,10 @@ The settings section has the following structure:
269
271
270
272
Each block can configure any of these settings separately, providing a more fine-grained control over what exists via `add_theme_support`. The settings declared at the top-level affect to all blocks, unless a particular block overwrites it. It's a way to provide inheritance and configure all blocks at once.
271
273
274
+
Note, however, that not all settings are relevant for all blocks. The settings section provides an opt-in/opt-out mechanism for themes, but it's the block's responsibility to add support for the features that are relevant to it. For example, if a block doesn't implement the `dropCap` feature, a theme can't enable it for such a block through `theme.json`.
275
+
276
+
#### Backward compatibility with add_theme_support
277
+
272
278
To retain backward compatibility, the existing `add_theme_support` declarations that configure the block editor are retrofit in the proper categories for the top-level section. For example, if a theme uses `add_theme_support('disable-custom-colors')`, it'll be the same as setting `settings.color.custom` to `false`. If the `theme.json` contains any settings, these will take precedence over the values declared via `add_theme_support`. This is the complete list of equivalences:
273
279
274
280
| add_theme_support | theme.json setting |
@@ -284,28 +290,6 @@ To retain backward compatibility, the existing `add_theme_support` declarations
284
290
|`editor-gradient-presets`| Provide the list of gradients via `color.gradients`. |
285
291
|`experimental-link-color`| Set `color.link` to `true`. |
286
292
287
-
Let's say a theme author wants to enable custom colors only for the paragraph block. This is how it can be done:
288
-
289
-
```json
290
-
{
291
-
"version": 1,
292
-
"settings": {
293
-
"color": {
294
-
"custom": false
295
-
},
296
-
"blocks": {
297
-
"core/paragraph": {
298
-
"color": {
299
-
"custom": true
300
-
}
301
-
}
302
-
}
303
-
}
304
-
}
305
-
```
306
-
307
-
Note, however, that not all settings are relevant for all blocks. The settings section provides an opt-in/opt-out mechanism for themes, but it's the block's responsibility to add support for the features that are relevant to it. For example, if a block doesn't implement the `dropCap` feature, a theme can't enable it for such a block through `theme.json`.
308
-
309
293
#### Presets
310
294
311
295
Presets are part of the settings section. They are values that are shown to the user via some UI controls. By defining them via `theme.json` the engine can do more for themes, such as automatically translate the preset name or enqueue the corresponding CSS classes and custom properties.
@@ -511,6 +495,98 @@ body {
511
495
512
496
Note that the name of the variable is created by adding `--` in between each nesting level and `camelCase` fields are transformed to `kebab-case`.
513
497
498
+
#### Settings examples
499
+
500
+
- Enable custom colors only for the paragraph block:
501
+
502
+
```json
503
+
{
504
+
"version": 1,
505
+
"settings": {
506
+
"color": {
507
+
"custom": false
508
+
},
509
+
"blocks": {
510
+
"core/paragraph": {
511
+
"color": {
512
+
"custom": true
513
+
}
514
+
}
515
+
}
516
+
}
517
+
}
518
+
```
519
+
520
+
- Disable border radius for the button block (borders only work in the plugin so far):
521
+
522
+
```json
523
+
{
524
+
"version": 1,
525
+
"settings": {
526
+
"core/button": {
527
+
"border": {
528
+
"customRadius": false
529
+
}
530
+
}
531
+
}
532
+
}
533
+
```
534
+
535
+
- Provide the group block a different palette than the rest:
0 commit comments