Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom Gutenberg block in WordPress?
Asked on Feb 26, 2026
Answer
Creating a custom Gutenberg block in WordPress involves using JavaScript and the WordPress Block Editor API. You'll need to set up a development environment and write the block's code using React and JSX.
<!-- BEGIN COPY / PASTE -->
// Register a custom block
wp.blocks.registerBlockType('my-plugin/custom-block', {
title: 'Custom Block',
icon: 'smiley',
category: 'common',
edit: function() {
return wp.element.createElement('p', null, 'Hello World, this is a custom block!');
},
save: function() {
return wp.element.createElement('p', null, 'Hello World, this is a custom block!');
}
});
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you have Node.js and npm installed to set up your development environment.
- Use the WordPress @wordpress/scripts package to simplify the build process with Webpack and Babel.
- Consider using a starter plugin or boilerplate to speed up the initial setup.
- Test your block thoroughly in the Block Editor to ensure compatibility and functionality.
Recommended Links:
