register_block_type() WordPress Function

register_block_type() is a function used to register new block types for use in the WordPress editor. This function takes two arguments: the first is a string containing the block name, and the second is an array of options for the block. The options array can contain various settings for the block, such as its title, description, category, and icon.

register_block_type( string|WP_Block_Type $block_type, array $args = array() ) #

Registers a block type. The recommended way is to register a block type using the metadata stored in the block.json file.


Parameters

$block_type

(string|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.json file is located, or a complete WP_Block_Type instance. In case a WP_Block_Type is provided, the $args parameter will be ignored.

$args

(array)(Optional) Array of block type arguments. Accepts any public property of WP_Block_Type. See WP_Block_Type::__construct() for information on accepted arguments.

Default value: array()


Top ↑

Return

(WP_Block_Type|false) The registered block type on success, or false on failure.


Top ↑

Source

File: wp-includes/blocks.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
5.8.0First parameter now accepts a path to the block.json file.
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.