register_block_pattern( string $pattern_name, array $pattern_properties )
Registers a new pattern.
Parameters Parameters
- $pattern_name
-
(string) (Required) Pattern name including namespace.
- $pattern_properties
-
(array) (Required) Array containing the properties of the pattern.
Return Return
(bool) True if the pattern was registered with success and false otherwise.
Source Source
File: wp-includes/class-wp-block-patterns-registry.php
function register_block_pattern( $pattern_name, $pattern_properties ) { return WP_Block_Patterns_Registry::get_instance()->register( $pattern_name, $pattern_properties ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Per the Block Patterns documentation in the Block Editor Handbook, the $pattern_properties array includes:
and the example function given is:
Feedback
As an addition to the category, I would like to give an example for those who did not know what syntax to use. Since a block pattern can be assigned to multiple categories you can use an array to place it in the right category. example:
how to define/register a category can be found here: https://developer.wordpress.org/reference/functions/register_block_pattern_category/ — By MangoWambo —
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.Feedback
Good call! Registering the block pattern straight from functions.php results in the editor crashing with an obscure JS error after opening the patterns pannel, without any PHP errors or warnings being triggered. Calling
register_block_pattern
inside the init hook solves this perfectly! Thanks! — By Jules Colle —