Skip to content

Commit d75cab8

Browse files
bphMamaduka
andauthored
Docs: Added copy and code for style_data (#69920)
Co-authored-by: bph <[email protected]> Co-authored-by: Mamaduka <[email protected]>
1 parent feb44ab commit d75cab8

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/reference-guides/block-api/block-styles.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@ The properties of the style array must include `name` and `label`:
6464
- `name`: The identifier of the style used to compute a CSS class.
6565
- `label`: A human-readable label for the style.
6666

67-
Besides the two mandatory properties, the styles properties array should also include an `inline_style` or a `style_handle` property:
67+
Besides the two mandatory properties, the styles properties array should also include an `inline_style` or a `style_handle` or a `style_data`property:
6868

6969
- `inline_style`: Contains inline CSS code that registers the CSS class required for the style.
7070
- `style_handle`: Contains the handle to an already registered style that should be enqueued in places where block styles are needed.
71+
- `style_data`: Contains a theme.json-like notation in an array of style properties.
7172

72-
It is also possible to set the `is_default` property to `true` to mark one of the block styles as the default one.
73+
It is also possible to set the `is_default` property to `true` to mark one of the block styles as the default one, should one be mising.
7374

7475
The following code sample registers a style for the quote block named "Blue Quote", and provides an inline style that makes quote blocks with the "Blue Quote" style have blue color:
7576

@@ -102,6 +103,29 @@ register_block_style(
102103
)
103104
);
104105
```
106+
Another way is using the `style_data`property, as in below code example. It adds a block style to the image block with an orange border and slightly rounded corners.
107+
108+
```php
109+
register_block_style(
110+
array( 'core/image' ),
111+
array(
112+
'name' => 'orange-border',
113+
'label' => __( 'Orange Border', 'pauli' ),
114+
'style_data'=> array(
115+
'border' => array(
116+
'color' => '#f5bc42',
117+
'style' => 'solid',
118+
'width' => '4px',
119+
'radius' => '15px'
120+
)
121+
)
122+
)
123+
);
124+
```
125+
Using the `style_data` property empowers the user to change it with the Global Styles UI via the **Editor > Styles**. The `style_data`property was added in WordPress 6.6.
126+
127+
More information via WordPress 6.6 Dev Note: [Section Styles](https://make.wordpress.org/core/2024/06/24/section-styles/).
128+
Also on the WordPress Developer Blog: [Styling sections, nested elements, and more with Block Style Variations in WordPress 6.6](https://developer.wordpress.org/news/2024/06/styling-sections-nested-elements-and-more-with-block-style-variations-in-wordpress-6-6/)
105129

106130
### unregister_block_style
107131

0 commit comments

Comments
 (0)