Skip to main content
Blocks in WordPress are registered on both the server and client-side using block.json metadata. This dual registration is crucial for enabling server-side features like dynamic rendering, block supports, block hooks, and style variations.
Always register blocks on the server. Client-only registration prevents server-side features from working correctly, including theme.json styling.

Server-side registration (PHP)

Block registration on the server uses the register_block_type() function called on the init hook:

Function parameters

The register_block_type() function accepts two parameters:
string
required
Path to the directory containing block.json, or the complete path to the metadata file if named differently.
array
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 the autoRegister 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 using registerBlockType from @wordpress/blocks:

Function parameters

The registerBlockType() function accepts two parameters:
string|object
required
Either the block type’s name as a string, or an object containing the block’s metadata (typically imported from block.json).
object
Object containing the block’s client-side settings, including edit and save.

Edit component

The edit property defines the React component used in the editor:

Save function

The save function returns static HTML saved to the database:
For dynamic blocks using a render callback or render.php, you can return null from the save function.

Registration flow

The complete registration process:
1

Define metadata

Create block.json with block configuration
2

Build assets

Run npm run build to compile JavaScript and CSS
3

Register on server

Call register_block_type() on the init hook in PHP
4

Register on client

Import and call registerBlockType() in JavaScript

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