block.json file simplifies defining and registering blocks by using the same JSON format to register the block on both the server and client (Block Editor).
Benefits of using block.json
Using ablock.json file provides several benefits:
- Performance: Block metadata is cached server-side, reducing overhead
- Consistency: Same definition used for both server and client registration
- Schema validation: JSON schema provides IDE autocomplete and validation
- Tooling: Build tools can automatically detect and process blocks
- Translation: Internationalization is handled automatically
Basic structure
Basic metadata properties
API version
number
required
Specifies the Block API version. Use
3 for the latest version unless you have specific requirements.Block name
string
required
The unique identifier for the block, including namespace (e.g.,
my-plugin/my-custom-block). Must contain a namespace prefix followed by a slash.Display title
string
required
The display title shown in the Block Inserter and block editor interface.
Category
string
required
The category under which the block appears in the Inserter. Common categories:
text- Text-based contentmedia- Images, video, audiodesign- Layout and design elementswidgets- Utility blockstheme- Theme-related blocks
Icon
Description
string
A short description providing context beyond the title.
Keywords
array
Array of keywords to help users find the block when searching.
Text domain
string
The text domain for internationalization, typically matching your plugin slug.
File references
Specify the files that control block behavior and appearance:Editor script
string|array
JavaScript file(s) loaded only in the Block Editor. Typically points to the bundled
index.js.Editor style
string|array
CSS file(s) for styling within the Block Editor only.
Script
string|array
JavaScript file(s) loaded in both the Block Editor and front end.
Style
string|array
CSS file(s) applied in both the Block Editor and front end.
View script
string|array
JavaScript file(s) loaded solely on the front end.
Render template
string
Path to a PHP template file for server-side rendering (dynamic blocks).
For file paths, use the
file: prefix. You can also reference handles registered via wp_register_script or wp_register_style.Block attributes
Attributes define data storage for the block:Attribute properties
- type: Data type (
string,number,boolean,array,object) - default: Default value if not set
- source: How to extract value from saved content
- selector: CSS selector for source extraction
Block supports
Thesupports property enables common features:
Complete example
Here’s a completeblock.json for a copyright block:
Next steps
Block attributes
Deep dive into attribute configuration
Block supports
Learn about all available supports