On this page
Create custom blocks
The Gutenberg editor gives a lot of options out of the box, but to really harness the power Gutenberg gives you, a custom block written in a ReactJS syntax, wrapped with the Gutenberg block API is the way to go.
This does not only let you create the block as standard HTML, CSS and JS, but you can also use the powerful Gutenberg block API to create rich and advanced user interfaces.
The best way to quickly get started to create your own custom blocks is to use the provided Example block sub-module.
You'll need NodeJS (and NPM) installed for Javascript and CSS transpiling tools.
- Copy the
gutenberg/modules/example_block
folder to your custom modules folder and rename it. In our case, we're usingmodules/custom/my_custom_blocks
- Rename
example_block.*.yml
files tomy_custom_blocks.*.yml
andpackage.example.json
topackage.json
- Rename
example_block
reference tomy_custom_blocks
onmy_custom_blocks.gutenberg.yml
andpackage.json
files - Run
npm install
on themy_custom_blocks
folder - Active the
my_custom_blocks
Drupal Module - Run
npm run build
on themy_custom_blocks
folder to create the new js Code - Run
npm start
on themy_custom_blocks
folder to continues watch changes during development - The new Block is now available. Search for the Block Title
This should be the file structure of your newly created module:
Resources on custom block development
- Blocks (WordPress/gutenberg.git docs)
- Writing Your First Block Type (WordPress.org docs)
- Your best friends: RichText and InnerBlocks components
- Also you can check how core blocks are implemented. Find a middle term between reusing core blocks, their style or their functionalities and creating blocks from scratch.
For more details on how to build advanced blocks visit https://developer.wordpress.org/block-editor/developers/block-api/
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion