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 Mar 09, 2026
Answer
Creating a custom block for the WordPress block editor involves using the Block API, which allows you to define and register blocks using JavaScript. This process typically requires some knowledge of JavaScript and React, as the block editor is built with these technologies.
<!-- 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() {
return wp.element.createElement('p', {}, 'Hello from the block editor!');
},
save: function() {
return wp.element.createElement('p', {}, 'Hello from the frontend!');
}
});
<!-- END COPY / PASTE -->Additional Comment:
- The above code should be added to a JavaScript file that is enqueued in the WordPress admin using the "enqueue_block_editor_assets" action.
- Ensure you have the necessary development environment set up, including Node.js and npm, to build and bundle your block scripts.
- Consider using the "@wordpress/create-block" package to scaffold a new block plugin with all the necessary configurations.
Recommended Links:
