On this page
register_block_type( string|WP_Block_Type $block_type, array $args = array() ): WP_Block_Type|false
Registers a block type. The recommended way is to register a block type using the metadata stored in the block.json file.
Parameters
$block_typestring|WP_Block_Type Required-
Block type name including namespace, or alternatively a path to the JSON file with metadata definition for the block, or a path to the folder where the
block.jsonfile is located, or a complete WP_Block_Type instance.
In case a WP_Block_Type is provided, the $args parameter will be ignored. $argsarray Optional-
Array of block type arguments. Accepts any public property of
WP_Block_Type. See WP_Block_Type::__construct() for information on accepted arguments.More Arguments from WP_Block_Type::__construct( ... $args )
Array or string of arguments for registering a block type. Any arguments may be defined, however the ones described below are supported by default.
api_versionstringBlock API version.titlestringHuman-readable block type label.categorystring|nullBlock type category classification, used in search interfaces to arrange block types by category.parentstring[]|nullSetting parent lets a block require that it is only available when nested within the specified blocks.ancestorstring[]|nullSetting ancestor makes a block available only inside the specified block types at any position of the ancestor's block subtree.iconstring|nullBlock type icon.descriptionstringA detailed block type description.keywordsstring[]Additional keywords to produce block type as result in search interfaces.textdomainstring|nullThe translation textdomain.stylesarray[]Alternative block styles.variationsarray[]Block variations.supportsarray|nullSupported features.examplearray|nullStructured data for the block preview.render_callbackcallable|nullBlock type render callback.attributesarray|nullBlock type attributes property schemas.uses_contextstring[]Context values inherited by blocks of this type.provides_contextstring[]|nullContext provided by blocks of this type.editor_script_handlesstring[]Block type editor only script handles.script_handlesstring[]Block type front end and editor script handles.view_script_handlesstring[]Block type front end only script handles.editor_style_handlesstring[]Block type editor only style handles.style_handlesstring[]Block type front end and editor style handles.
Default:
array()
Return
WP_Block_Type|false The registered block type on success, or false on failure.
Source
File: wp-includes/blocks.php. View all references
function register_block_type( $block_type, $args = array() ) {
if ( is_string( $block_type ) && file_exists( $block_type ) ) {
return register_block_type_from_metadata( $block_type, $args );
}
return WP_Block_Type_Registry::get_instance()->register( $block_type, $args );
}
Related
Uses
| Uses | Description |
|---|---|
| register_block_type_from_metadata() wp-includes/blocks.php | Registers a block type from the metadata stored in the |
| WP_Block_Type_Registry::get_instance() wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/register_block_type