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
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.The display title for your block shown in the Inserter and other areas. Can be translated.
Optional properties
The version of the Block API used by the block. The most recent version is
3, introduced in WordPress 6.3.Blocks are grouped into categories in the Inserter. Core categories include:
text, media, design, widgets, theme, and embed.An icon to identify the block. Can be any WordPress Dashicon slug or custom SVG.
A short description shown in the block inspector. Can be translated.
Search terms to help users discover the block. Can be translated.
The current version of the block, used for cache invalidation.
The gettext text domain for internationalization.
Defines the structured data needs of the block. See Attributes for details.
Context provided for descendent blocks. Maps context name to attribute.
Array of context names to inherit from ancestor blocks.
Custom CSS selectors for theme.json styles. Available since WordPress 6.3.
Alternative block styles. The
label property can be translated.Structured data for the block preview in the Inspector.
Block variations that share common functionality. Available since WordPress 5.9.
Restricts block to only be available nested within specified blocks.
Makes block available anywhere within specified block subtrees. Available since WordPress 6.0.
Specifies which blocks can be direct children. Available since WordPress 6.5.
Asset properties
Scripts enqueued only in the editor context. Can be a registered handle or file path.
Scripts enqueued in both editor and frontend.
Scripts enqueued only on the frontend. Available since WordPress 5.9.
Script modules enqueued only on the frontend. Available since WordPress 6.5.
Styles enqueued only in the editor.
Styles enqueued in both editor and frontend.
Styles enqueued only on the frontend. Available since WordPress 6.5.
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 withfile: and are relative to the block.json location.
Dependency files
For script and style assets, WordPress automatically detects.asset.php files:
.asset.php file should return:
Internationalization
WordPress can automatically translate fields marked as translatable when thetextdomain property is set. Translatable fields include:
titledescriptionkeywordsstyles[].labelvariations[].titlevariations[].descriptionvariations[].keywords
PHP translation
In PHP, properties are wrapped in_x() function calls:
JavaScript translation
Frontend asset enqueueing
Assets specified inscript, viewScript, style, and viewStyle are only enqueued when the block is present on the page, optimizing performance.