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 23, 2026
Answer
Creating a custom Gutenberg block in WordPress involves using JavaScript and the WordPress Block Editor API. This process allows you to add unique content elements to your posts and pages.
<!-- BEGIN COPY / PASTE -->
// Register a new block type
wp.blocks.registerBlockType('my-plugin/my-custom-block', {
title: 'My Custom Block',
icon: 'smiley',
category: 'common',
edit: function(props) {
return wp.element.createElement('p', {}, 'Hello, World!');
},
save: function(props) {
return wp.element.createElement('p', {}, 'Hello, World!');
}
});
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you have a development environment set up with Node.js and npm.
- Use the WordPress Scripts package to simplify the build process.
- Consider using a block scaffolding tool like Create Guten Block for faster setup.
- Test your block thoroughly in different browsers and screen sizes.
Recommended Links:
