WP_Block_Type_Registry::register( string|WP_Block_Type $name, array $args = array() ): WP_Block_Type|false

Registers a block type.


Top ↑

See also

Top ↑


$name string|WP_Block_Type Required
Block type name including namespace, or alternatively 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.
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_version string
    Block API version.
  • title string
    Human-readable block type label.
  • category string|null
    Block type category classification, used in search interfaces to arrange block types by category.
  • parent string[]|null
    Setting parent lets a block require that it is only available when nested within the specified blocks.
  • ancestor string[]|null
    Setting ancestor makes a block available only inside the specified block types at any position of the ancestor's block subtree.
  • icon string|null
    Block type icon.
  • description string
    A detailed block type description.
  • keywords string[]
    Additional keywords to produce block type as result in search interfaces.
  • textdomain string|null
    The translation textdomain.
  • styles array[]
    Alternative block styles.
  • variations array[]
    Block variations.
  • selectors array
    Custom CSS selectors for theme.json style generation.
  • supports array|null
    Supported features.
  • example array|null
    Structured data for the block preview.
  • render_callback callable|null
    Block type render callback.
  • attributes array|null
    Block type attributes property schemas.
  • uses_context string[]
    Context values inherited by blocks of this type.
  • provides_context string[]|null
    Context provided by blocks of this type.
  • editor_script_handles string[]
    Block type editor only script handles.
  • script_handles string[]
    Block type front end and editor script handles.
  • view_script_handles string[]
    Block type front end only script handles.
  • editor_style_handles string[]
    Block type editor only style handles.
  • style_handles string[]
    Block type front end and editor style handles.

Default: array()

Top ↑


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

Top ↑


File: wp-includes/class-wp-block-type-registry.php. View all references

public function register( $name, $args = array() ) {
	$block_type = null;
	if ( $name instanceof WP_Block_Type ) {
		$block_type = $name;
		$name       = $block_type->name;

	if ( ! is_string( $name ) ) {
			__( 'Block type names must be strings.' ),
		return false;

	if ( preg_match( '/[A-Z]+/', $name ) ) {
			__( 'Block type names must not contain uppercase characters.' ),
		return false;

	$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
	if ( ! preg_match( $name_matcher, $name ) ) {
			__( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ),
		return false;

	if ( $this->is_registered( $name ) ) {
			/* translators: %s: Block name. */
			sprintf( __( 'Block type "%s" is already registered.' ), $name ),
		return false;

	if ( ! $block_type ) {
		$block_type = new WP_Block_Type( $name, $args );

	$this->registered_block_types[ $name ] = $block_type;

	return $block_type;

Top ↑


Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.