Gutenberg – Registering a new block using registerBlockType()

To register a new block we will use the registerBlockType() function, view the function on GitHub. This function registers a new block by providing a unique name and an object (attributes) defining its behavior.

Once registered, the block is made available as an option to any editor interface where blocks are enabled. There are two parameters the function needs to register and enable our new block.

  • name [string] –  Block names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-block or my-theme/my-custom-block
  • settings [Object] – The settings object builds predefined properties (called Attributes) that your block will use for configuration and display options. Data properties are technically not required but there are a handful of preliminary attributes that need to be defined for your block to enable.
// Registering a block 
registerBlockType( 'my-plugin/my-custom-block', {} );

Leave a Reply

Your email address will not be published. Required fields are marked *

Join Newsletter

About Me

Senior Application Developer. Focused on WordPress, Magento, Web Security & Server Optimization. I also contribute to open source projects when I can.

I have a growing family and spend most of my free time with them, working on my personal health and fitness or small home improvement projects.