Optional. Block HTML markup for the pattern. If not provided, the content will be retrieved from the filePath if set. If both content and filePath are not set, the pattern will not be registered.
$descriptionstring
Optional. Visually hidden text used to describe the pattern in the inserter. A description is optional, but is strongly encouraged when the title does not fully describe what the pattern does. The description will help users discover the pattern while searching.
$viewportWidthint
Optional. The intended width of the pattern to allow for a scaled preview within the pattern inserter.
$inserterbooldefault: true
Optional. Determines whether the pattern is visible in inserter. To hide a pattern so that it can only be inserted programmatically, set this to false.
$categoriesstring[]
Optional. A list of registered pattern categories used to group block patterns. Block patterns can be shown on multiple categories. A category must be registered separately in order to be used here.
$keywordsstring[]
Optional. A list of aliases or keywords that help users discover the pattern while searching.
$blockTypesstring[]
Optional. A list of block names including namespace that could use the block pattern in certain contexts (placeholder, transforms). The block pattern is available in the block editor inserter regardless of this list of block names. Certain blocks support further specificity besides the block name (e.g. for core/template-part you can specify areas like core/template-part/header or core/template-part/footer).
$postTypesstring[]
Optional. An array of post types that the pattern is restricted to be used with. The pattern will only be available when editing one of the post types passed on the array. For all the other post types not part of the array the pattern is not available at all.
$templateTypesstring[]
Optional. An array of template types where the pattern fits.
$filePathstring
Optional. The full path to the file containing the block pattern content.
Return
bool
True if the pattern was registered with success and false otherwise.
89publicfunctionregister($pattern_name,$pattern_properties){90if(!isset($pattern_name)||!is_string($pattern_name)){91_doing_it_wrong(92__METHOD__,93__('Pattern name must be a string.'),94'5.5.0'95);96returnfalse;97}9899if(!isset($pattern_properties['title'])||!is_string($pattern_properties['title'])){100_doing_it_wrong(101__METHOD__,102__('Pattern title must be a string.'),103'5.5.0'104);105returnfalse;106}107108if(!isset($pattern_properties['filePath'])){109if(!isset($pattern_properties['content'])||!is_string($pattern_properties['content'])){110_doing_it_wrong(111__METHOD__,112__('Pattern content must be a string.'),113'5.5.0'114);115returnfalse;116}117}118119$pattern=array_merge(120$pattern_properties,121array('name'=>$pattern_name)122);123124$this->registered_patterns[$pattern_name]=$pattern;125126// If the pattern is registered inside an action other than `init`, store it127// also to a dedicated array. Used to detect deprecated registrations inside128// `admin_init` or `current_screen`.129if(current_action()&&'init'!==current_action()){130$this->registered_patterns_outside_init[$pattern_name]=$pattern;131}132133returntrue;134}
History
Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.5.0
Added support for the filePath property.from the docblock
6.2.0
Added support for the templateTypes property.from the docblock
6.1.0
Added support for the postTypes property.from the docblock
5.8.0
Added support for the blockTypes property.from the docblock
5.5.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-block-patterns-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.