Create custom Gutenberg blocks for WordPress using React and the Block Editor API — register, edit, save, and publish your blocks.

Abdur Razzak
Full-Stack Web Developer
Gutenberg, the WordPress block editor, is built with React. Every block consists of two parts: the edit function (what editors see in the admin) and the save function (the static HTML saved to the database). Blocks are registered with registerBlockType() using a unique namespace/block-name identifier. Understanding this separation is key to building effective custom blocks.
Use @wordpress/scripts (npx @wordpress/create-block my-block) to scaffold a new block plugin with Webpack, Babel, and the WordPress block scripts configured. This creates a plugin structure with block.json (block metadata), edit.js (editor component), save.js (static output), and index.js (registration). Run npm start for development mode with hot reload in the block editor.
block.json is the block's metadata file: name, version, title, description, category, icon, attributes, editorScript, and style. Attributes define the data your block stores — title (string), imageUrl (string), isLarge (boolean). WordPress uses block.json to register the block on both PHP and JavaScript sides. Store all block data as attributes, never as hardcoded values in save.js.
The edit component is a React component that receives attributes and setAttributes props. Use WordPress's built-in components: RichText for formatted text input, MediaUpload for image selection, InspectorControls for sidebar panel controls, PanelBody, TextControl, ToggleControl. These components integrate with the block editor's undo/redo system and follow WordPress design patterns automatically.
The save function returns the static HTML stored in the database. Unlike the edit function, save cannot have dynamic behavior — it is a pure function of the block's attributes. Use WordPress's useBlockProps for the root element to apply block gap and alignment styles. If you need dynamic output (PHP rendering), use a server-side-rendered block with a render_callback in register_block_type() and return null from save.
Package your block plugin for distribution by running npm run build, which creates optimized production JavaScript and CSS files. Include only the build folder, block.json, and the main PHP plugin file in your distribution. Submit to the WordPress.org plugin repository for free distribution. For commercial blocks, use platforms like Freemius or EDD (Easy Digital Downloads) to manage licensing and updates.