Blocks are the fundamental element of the WordPress Block Editor. They are the primary way plugins and themes register functionality and extend the editor’s capabilities.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/WordPress/gutenberg/llms.txt
Use this file to discover all available pages before exploring further.
What is a Block?
A block is a discrete unit of content or functionality in the WordPress editor. Each block encapsulates its own:- Data structure (attributes)
- User interface (edit component)
- Saved output (save function or render callback)
- Behavior (transforms, variations, styles)
Block Registration Methods
You can register blocks using two approaches:1. JavaScript-only Registration
2. block.json Metadata (Recommended)
The recommended approach is to use ablock.json file that defines your block’s metadata:
Core Block API Concepts
Attributes
Define the data structure and how it’s stored in post content
Supports
Enable editor features like colors, spacing, and typography
Patterns
Create reusable block layouts for common designs
Inner Blocks
Build container blocks that can nest other blocks
Block Naming Convention
The block name is stored in post content with every post using that block. Changing it later requires database migration.
Block Types
Static Blocks
Blocks that render entirely in JavaScript and save static HTML:Dynamic Blocks
Blocks that render on the server using PHP:Block API Version
TheapiVersion field determines which version of the Block API your block uses:
- Version 1: Original API (deprecated)
- Version 2: Introduces automatic wrapper element handling
- Version 3: Current version with enhanced features and performance
TypeScript Support
Gutenberg provides TypeScript type definitions for the Block API:Block Data Flow
Understanding how data flows through a block:Block Collections
Group related blocks together in the inserter:Best Practices
Use block.json for registration
Use block.json for registration
Always use
block.json metadata files. They enable better performance, automatic translations, and server-side registration.Follow naming conventions
Follow naming conventions
Use a unique, descriptive namespace that represents your plugin or theme. This prevents conflicts with other blocks.
Leverage Block Supports
Leverage Block Supports
Use the supports API instead of building custom controls for common features like colors, spacing, and typography.
Consider dynamic rendering
Consider dynamic rendering
For blocks with server-side data or complex logic, use dynamic blocks with PHP render callbacks.
Next Steps
Register Your First Block
Learn the complete registration process
Define Block Attributes
Understand how to structure block data