Skip to main content
Starting with WordPress 5.8, the recommended way to register block types is using the block.json metadata file. This file serves as the canonical definition for both PHP (server-side) and JavaScript (client-side) registration.

Basic example

Block properties

Required properties

string
required
The unique identifier for the block. Must be structured as namespace/block-name where namespace is your plugin or theme name. Can only contain lowercase alphanumeric characters, dashes, and one forward slash.
string
required
The display title for your block shown in the Inserter and other areas. Can be translated.

Optional properties

number
default:"1"
The version of the Block API used by the block. The most recent version is 3, introduced in WordPress 6.3.
string
Blocks are grouped into categories in the Inserter. Core categories include: text, media, design, widgets, theme, and embed.
string
An icon to identify the block. Can be any WordPress Dashicon slug or custom SVG.
string
A short description shown in the block inspector. Can be translated.
string[]
default:"[]"
Search terms to help users discover the block. Can be translated.
string
The current version of the block, used for cache invalidation.
string
The gettext text domain for internationalization.
object
default:"{}"
Defines the structured data needs of the block. See Attributes for details.
object
default:"{}"
Context provided for descendent blocks. Maps context name to attribute.
string[]
default:"[]"
Array of context names to inherit from ancestor blocks.
object
default:"{}"
Custom CSS selectors for theme.json styles. Available since WordPress 6.3.
object
default:"{}"
Features enabled for the block. See Supports for details.
array
default:"[]"
Alternative block styles. The label property can be translated.
object
Structured data for the block preview in the Inspector.
object[]
Block variations that share common functionality. Available since WordPress 5.9.
string[]
Restricts block to only be available nested within specified blocks.
string[]
Makes block available anywhere within specified block subtrees. Available since WordPress 6.0.
string[]
Specifies which blocks can be direct children. Available since WordPress 6.5.

Asset properties

string | string[]
Scripts enqueued only in the editor context. Can be a registered handle or file path.
string | string[]
Scripts enqueued in both editor and frontend.
string | string[]
Scripts enqueued only on the frontend. Available since WordPress 5.9.
string | string[]
Script modules enqueued only on the frontend. Available since WordPress 6.5.
string | string[]
Styles enqueued only in the editor.
string | string[]
Styles enqueued in both editor and frontend.
string | string[]
Styles enqueued only on the frontend. Available since WordPress 6.5.
string
PHP file for server-side rendering. Available since WordPress 6.1.
The file receives three variables:
  • $attributes (array) - Block attributes
  • $content (string) - Block default content
  • $block (WP_Block) - Block instance

Asset file paths

File paths must be prefixed with file: and are relative to the block.json location.

Dependency files

For script and style assets, WordPress automatically detects .asset.php files:
The .asset.php file should return:

Internationalization

WordPress can automatically translate fields marked as translatable when the textdomain property is set. Translatable fields include:
  • title
  • description
  • keywords
  • styles[].label
  • variations[].title
  • variations[].description
  • variations[].keywords

PHP translation

In PHP, properties are wrapped in _x() function calls:

JavaScript translation

Frontend asset enqueueing

Assets specified in script, viewScript, style, and viewStyle are only enqueued when the block is present on the page, optimizing performance.