函数原型
register_block_pattern( string $pattern_name, array $pattern_properties ): bool
函数描述
Registers a new block pattern.
是否弃用
未弃用
函数参数
-
$pattern_name
string
Required - Block pattern name including namespace.
-
$pattern_properties
array
Required - List of properties for the block pattern.
See WP_Block_Patterns_Registry::register() for accepted arguments.More Arguments from WP_Block_Patterns_Registry::register( … $pattern_properties )
List of properties for the block pattern.
titlestringRequired. A human-readable title for the pattern.contentstringRequired. Block HTML markup for the pattern.descriptionstringOptional. 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.viewportWidthintOptional. The intended width of the pattern to allow for a scaled preview within the pattern inserter.categoriesarrayOptional. 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.blockTypesarrayOptional. 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. forcore/template-partyou can specify areas likecore/template-part/headerorcore/template-part/footer).keywordsarrayOptional. A list of aliases or keywords that help users discover the pattern while searching.
函数返回值
bool True if the pattern was registered with success and false otherwise.
函数位置
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 5.5.0 | Introduced. |

