What is a block?
“Block” is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage. The idea combines concepts of what in WordPress today we achieve with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience.Block registration
Every block starts by registering a new block type definition. The recommended method is to register blocks with both PHP (server-side) and JavaScript (client-side) using theblock.json metadata file.
Basic registration
Server-side registration
Block structure
A block consists of several key components:- Metadata - Block configuration defined in
block.json - Attributes - Structured data that defines the block’s content
- Edit function - React component for the editor interface
- Save function - Defines how the block is saved to post content
- Supports - Features and capabilities enabled for the block
Key concepts
Block names
The name for a block is a unique string that identifies a block. Names must be structured asnamespace/block-name, where namespace is the name of your plugin or theme.
Block attributes
Attributes provide the structured data needs of a block. They can exist in different forms when serialized, but are declared together under a common interface.Block context
Block context allows ancestor blocks to provide values that descendent blocks can consume without explicit awareness of the provider.Benefits of using block.json
Registering blocks with theblock.json metadata file provides multiple benefits:
- Performance - Lazy loading of assets when blocks are present on the page
- Server-side registration - Blocks are available via the Block Type REST API
- Block Directory - Metadata can be extracted for the WordPress Plugins Directory
- Development tooling - Schema validation and autocomplete in supported editors
API reference
The Block API consists of several key areas:- Metadata - Block configuration in block.json
- Registration - Registering blocks with JavaScript
- Attributes - Defining block data structure
- Context - Sharing data between blocks
- Supports - Enabling block features
- Selectors - Customizing CSS selectors
- Deprecation - Handling block updates
- Annotations - Highlighting content