register_block_style( string $block_name, array $style_properties ): bool
Registers a new block style.
Parameters
-
$block_name
string Required -
Block type name including namespace.
-
$style_properties
array Required -
Array containing the properties of the style name, label, style_handle (name of the stylesheet to be enqueued), inline_style (string containing the CSS to be added).
Return
bool True if the block style was registered with success and false otherwise.
Source
File: wp-includes/blocks.php
.
View all references
function register_block_style( $block_name, $style_properties ) {
return WP_Block_Styles_Registry::get_instance()->register( $block_name, $style_properties );
}
Changelog
Version | Description |
---|---|
5.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
The only mandatory properties of the
$style_properties
array arename
andlabel
:name
: the identifier of the style used to compute a CSS class.label
: a human-readable label for the style.The array can optionally include
inline_style
orstyle_handle
, in order to choose how to load the required CSS:inline_style
: contains inline CSS code that registers the CSS class required for the style. All inline block styles will appear in thehead
tag.style_handle
: contains the handle to an already registered style that should be enqueued in places where block styles are needed. Using this option gives you more control over where to enqueue the CSS.Also optional: set the
is_default
property totrue
to mark one of the block styles as the default one.Tip: to find the correct block name, open the block editor, launch the browser console and type
wp.blocks.getBlockTypes()
. You will see the complete list of block names (from core or third-party).Complete example:
For more information, see the Developer Handbook.