Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom Gutenberg block for a portfolio section? Pending Review
Asked on Mar 27, 2026
Answer
Creating a custom Gutenberg block for a portfolio section involves using the WordPress Block Editor API and some JavaScript to define the block's functionality and appearance. This process requires some coding knowledge, particularly with JavaScript and React.
<!-- BEGIN COPY / PASTE -->
// Register a custom Gutenberg block
wp.blocks.registerBlockType('myplugin/portfolio-block', {
title: 'Portfolio',
icon: 'portfolio',
category: 'common',
edit: function(props) {
return wp.element.createElement(
'div',
{ className: props.className },
'Portfolio Block Content'
);
},
save: function() {
return wp.element.createElement(
'div',
null,
'Portfolio Block Content'
);
}
});
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you enqueue your block's JavaScript file using the "enqueue_block_editor_assets" action in your theme or plugin.
- Use "npm" and "webpack" to manage dependencies and build processes if your block becomes complex.
- Consider using the "@wordpress/scripts" package for a streamlined setup.
- Test your block thoroughly in different themes to ensure compatibility.
Recommended Links:
