Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom block for the WordPress block editor?
Asked on Jan 21, 2026
Answer
Creating a custom block for the WordPress block editor involves using JavaScript, specifically React, to define the block's behavior and appearance. You'll typically use the `@wordpress/scripts` package to streamline the development process.
<!-- 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 Node.js and npm installed to use the `@wordpress/scripts` package.
- Run `npx @wordpress/create-block my-custom-block` to scaffold a new block plugin.
- Customize the `edit` and `save` functions to define how your block appears in the editor and on the front end.
- Use WordPress's built-in components and hooks for enhanced functionality.
Recommended Links:
