Registers a new block pattern.
Parameters
$pattern_name
stringrequired- Block pattern name including namespace.
$pattern_properties
arrayrequired- List of properties for the block pattern.
See WP_Block_Patterns_Registry::register() for accepted arguments.
Source
function register_block_pattern( $pattern_name, $pattern_properties ) {
return WP_Block_Patterns_Registry::get_instance()->register( $pattern_name, $pattern_properties );
}
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |
Per the Block Patterns documentation in the Block Editor Handbook, the $pattern_properties array includes:
and the example function given is:
how to define/register a category can be found here: https://developer.wordpress.org/reference/functions/register_block_pattern_category/
The docs & handbook don’t seem to mention it, but I gather
register_block_pattern()
should be called from a handler attached to theinit
hook.register_block_pattern
inside the init hook solves this perfectly! Thanks!Just a heads up for block theme developers: since WordPress 6.0 you can also register patterns in a block theme simply by placing PHP files with patterns in your theme’s
/patterns
subfolder.If the core block patterns are removed via:
Make sure that there is at least one block pattern category registered. The block editor crashes if none are present.
A basic example of how to register a new pattern block.