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/reference-guides/block-api/block-styles.md
+26-2
Original file line number
Diff line number
Diff line change
@@ -64,12 +64,13 @@ The properties of the style array must include `name` and `label`:
64
64
-`name`: The identifier of the style used to compute a CSS class.
65
65
-`label`: A human-readable label for the style.
66
66
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:
68
68
69
69
-`inline_style`: Contains inline CSS code that registers the CSS class required for the style.
70
70
-`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.
71
72
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.
73
74
74
75
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:
75
76
@@ -102,6 +103,29 @@ register_block_style(
102
103
)
103
104
);
104
105
```
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/)
0 commit comments