block.json metadata. This dual registration is crucial for enabling server-side features like dynamic rendering, block supports, block hooks, and style variations.
Server-side registration (PHP)
Block registration on the server uses theregister_block_type() function called on the init hook:
Function parameters
Theregister_block_type() function accepts two parameters:
Path to the directory containing
block.json, or the complete path to the metadata file if named differently.Optional arguments for the block type. Can include
render_callback for dynamic rendering.With render callback
For dynamic blocks, provide a render callback:PHP-only blocks with auto-registration
For blocks that only need server-side rendering, use theautoRegister flag:
PHP-only blocks with
autoRegister: true automatically appear in the editor without requiring JavaScript registration.Client-side registration (JavaScript)
When the block is registered on the server, register client-side settings usingregisterBlockType from @wordpress/blocks:
Function parameters
TheregisterBlockType() function accepts two parameters:
Either the block type’s name as a string, or an object containing the block’s metadata (typically imported from
block.json).Object containing the block’s client-side settings, including
edit and save.Edit component
Theedit property defines the React component used in the editor:
Save function
Thesave function returns static HTML saved to the database:
Registration flow
The complete registration process:Complete example
block.json
plugin.php
src/index.js
Importing block.json
You can import
block.json directly into JavaScript when using @wordpress/scripts build process:Benefits of dual registration
Registering blocks on both server and client enables:- Dynamic rendering: Server-side HTML generation
- Block supports: Features like color, typography, spacing
- Theme.json styling: Global styles from theme configuration
- Block patterns: Reusable block compositions
- Block variations: Pre-configured block versions
- Block hooks: Programmatic block insertion
Next steps
Block wrapper
Learn how to properly wrap your block markup
Dynamic blocks
Understand server-side rendering