WP_Block_Type::__construct( string $block_type, array|string $args = array() )



Will populate object properties from the provided arguments.

See also


Block type name including namespace.
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.
  • allowed_blocks string[]|null
    Limits which block types can be inserted as children of this block type.
  • 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.
  • variation_callback callable|null
    Block type variations 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.
  • block_hooks string[]
    Block hooks.
  • 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.
  • view_style_handles string[]
    Block type front end only style handles.



public function __construct( $block_type, $args = array() ) {
	$this->name = $block_type;

	$this->set_props( $args );


6.5.0Added the view_style_handles property.
6.4.0Added the block_hooks property.
6.3.0Added the selectors property.
6.1.0Added the editor_script_handles, script_handles, view_script_handles, editor_style_handles, andstyle_handlesproperties. Deprecated theeditor_script,script,view_script,editor_style, andstyle` properties.
6.0.0Added the ancestor property.
5.9.0Added the view_script property.
5.8.0Added the variations property.
5.6.0Added the api_version property.
5.5.0Added the title, category, parent, icon, description, keywords, textdomain, styles, supports, example, uses_context, and provides_context properties.
Show 5 moreShow less

User Contributed Notes

  1. Skip to note 3 content

    The documentation above suggests that $args['script'] and $args['style'] will be loaded for the “front end”, however in fact it is loaded for both the editor and the front end. If you want certain scripts and styles to be loaded in the front end only, you have to independently load those after a conditional check. Unfortunately WP_Block_Type::__construct (and so register_block_type() and register_block_type_from_metadata()) does not support loading scripts or styles exclusively for the front end.

  2. Skip to note 4 content

    Note that the new to 5.9 view_script parameter only loads the script if render_callback is not defined. See /wp-includes/class-wp-block.php:266:

    if ( ! empty( $this->block_type->view_script ) && empty( $this->block_type->render_callback ) ) {
    	wp_enqueue_script( $this->block_type->view_script );

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