register_block_style() WordPress Function

The register_block_style() function is used to register a new block style for the block editor. This function takes two arguments: the name of the block style, and an optional array of style properties. Block styles are registered using the block_styles filter. This filter is passed an array of block styles, which can be modified by adding or removing styles. Once a block style is registered, it can be applied to any block in the editor. To do this, select the block you want to style, and then click the "Styles" dropdown in the block toolbar. Your custom block style will be listed under the "Custom" heading.

register_block_style( string $block_name, array $style_properties ) #

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 (name of the stylesheet to be enqueued), inline_style (string containing the CSS to be added).


Top ↑

Return

(bool) True if the block style was registered with success and false otherwise.


Top ↑

Source

File: wp-includes/blocks.php

function register_block_style( $block_name, $style_properties ) {
	return WP_Block_Styles_Registry::get_instance()->register( $block_name, $style_properties );
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.