WordPressWordPressGutenbergBlock EditorReactPlugin Development

WordPress Gutenberg Block Development: Build Custom Blocks

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

Abdur Razzak

Abdur Razzak

Full-Stack Web Developer

July 31, 2025 11 min read

Understanding Gutenberg Block Architecture

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.

Setting Up the Development Environment

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.

The block.json Manifest

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.

Building the Edit Component

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 and Static Output

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.

Distributing Your Block Plugin

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.

Share this article

All posts
#WordPress#Gutenberg#Block Editor#React#Plugin Development
Abdur Razzak — Full Stack Web Developer

Full-Stack Expert

MERN · React · Next.js · WordPress