block.json (metadata) guidance
Use this file when you’re editing block.json fields or choosing between script/styles fields.
Practical rules
- Treat
nameas stable API (renaming breaks existing content). - Prefer adding new functionality without changing saved markup; if markup must change, add a
deprecatedversion. - Keep assets scoped: editor assets should not ship to frontend unless needed.
API version + schema
WordPress 6.9+ requires apiVersion 3. The block.json schema now only validates blocks with apiVersion: 3. Older versions (1 or 2) trigger console warnings when SCRIPT_DEBUG is enabled.
Why apiVersion 3 matters:
- The post editor will be iframed if all registered blocks have apiVersion 3+.
- WordPress 7.0 will always use the iframe editor regardless of apiVersion.
- Benefits: style isolation (admin CSS won't affect editor content), correct viewport units (vw, vh), native media queries.
Migration checklist:
- Update
apiVersionto3in block.json. - Ensure all style handles are declared in block.json (styles not included won't load in the iframe).
- Test blocks that rely on third-party scripts (window scoping may differ).
- Add a
$schemato improve editor tooling and validation.
References:
- Block metadata: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/
- Block API versions: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/
- Iframe migration guide: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/block-migration-for-iframe-editor-compatibility/
- Block schema index: https://schemas.wp.org/
Modern asset fields to know
This is not a full schema; it’s a “what matters in practice” list:
editorScript/editorStyle: editor-only assets.script/style: shared assets.viewScript/viewStyle: frontend view assets.viewScriptModule: module-based frontend scripts (newer WP).render: points to a PHP render file for dynamic blocks (newer WP).
Helpful upstream references
- Block metadata reference (block.json):
- Block.json schema (editor tooling):