wp-block-development
Original:🇺🇸 English
Not Translated
1 scriptsChecked / no sensitive code detected
Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports, dynamic rendering (render.php/render_callback), deprecations/migrations, viewScript vs viewScriptModule, and @wordpress/scripts/@wordpress/create-block build and test workflows.
1installs
Sourceautomattic/agent-skills
Added on
NPX Install
npx skill4agent add automattic/agent-skills wp-block-developmentSKILL.md Content
WP Block Development
When to use
Use this skill for block work such as:
- creating a new block, or updating an existing one
- changing (scripts/styles/supports/attributes/render/viewScriptModule)
block.json - fixing “block invalid / not saving / attributes not persisting”
- adding dynamic rendering (/
render.php)render_callback - block deprecations and migrations (versions)
deprecated - build tooling for blocks (,
@wordpress/scripts,@wordpress/create-block)wp-env
Inputs required
- Repo root and target (plugin vs theme vs full site).
- The block name/namespace and where it lives (path to if known).
block.json - Target WordPress version range (especially if using modules / ).
viewScriptModule
Procedure
0) Triage and locate blocks
- Run triage:
node skills/wp-project-triage/scripts/detect_wp_project.mjs
- List blocks (deterministic scan):
node skills/wp-block-development/scripts/list_blocks.mjs
- Identify the block root (directory containing ) you’re changing.
block.json
If this repo is a full site ( present), be explicit about which plugin/theme contains the block.
wp-content/1) Create a new block (if needed)
If you are creating a new block, prefer scaffolding rather than hand-rolling structure:
- Use to scaffold a modern block/plugin setup.
@wordpress/create-block - If you need Interactivity API from day 1, use the interactive template.
Read:
references/creating-new-blocks.md
After scaffolding:
- Re-run the block list script and confirm the new block root.
- Continue with the remaining steps (model choice, metadata, registration, serialization).
2) Ensure apiVersion 3 (WordPress 6.9+)
WordPress 6.9 enforces in the block.json schema. Blocks with apiVersion 2 or lower trigger console warnings when is enabled.
apiVersion: 3SCRIPT_DEBUGWhy this matters:
- WordPress 7.0 will run the post editor in an iframe regardless of block apiVersion.
- apiVersion 3 ensures your block works correctly inside the iframed editor (style isolation, viewport units, media queries).
Migration: Changing from version 2 to 3 is usually as simple as updating the field in . However:
apiVersionblock.json- Test in a local environment with the iframe editor enabled.
- Ensure any style handles are included in (styles missing from the iframe won't apply).
block.json - Third-party scripts attached to a specific may have scoping issues.
window
Read:
- (apiVersion and schema details)
references/block-json.md
3) Pick the right block model
- Static block (markup saved into post content): implement ; keep attributes serialization stable.
save() - Dynamic block (server-rendered): use in
render(orblock.jsonin PHP) and keeprender_callbackminimal orsave().null - Interactive frontend behavior:
- Prefer for modern module-based view scripts where supported.
viewScriptModule - If you're working primarily on directives or stores, also use
data-wp-*.wp-interactivity-api
- Prefer
4) Update block.json
safely
block.jsonMake changes in the block’s , then confirm registration matches metadata.
block.jsonFor field-by-field guidance, read:
references/block-json.md
Common pitfalls:
- changing breaks compatibility (treat it as stable API)
name - changing saved markup without adding causes “Invalid block”
deprecated - adding attributes without defining source/serialization correctly causes “attribute not saving”
5) Register the block (server-side preferred)
Prefer PHP registration using metadata, especially when:
- you need dynamic rendering
- you need translations ()
wp_set_script_translations - you need conditional asset loading
Read and apply:
references/registration.md
6) Implement edit/save/render patterns
Follow wrapper attribute best practices:
- Editor:
useBlockProps() - Static save:
useBlockProps.save() - Dynamic render (PHP):
get_block_wrapper_attributes()
Read:
references/supports-and-wrappers.md- (if dynamic)
references/dynamic-rendering.md
7) Inner blocks (block composition)
If your block is a “container” that nests other blocks, treat Inner Blocks as a first-class feature:
- Use to integrate inner blocks with wrapper props.
useInnerBlocksProps() - Keep migrations in mind if you change inner markup.
Read:
references/inner-blocks.md
8) Attributes and serialization
Before changing attributes:
- confirm where the attribute value lives (comment delimiter vs HTML vs context)
- avoid the deprecated attribute source
meta
Read:
references/attributes-and-serialization.md
9) Migrations and deprecations (avoid "Invalid block")
If you change saved markup or attributes:
- Add a entry (newest → oldest).
deprecated - Provide for old versions and an optional
saveto normalize attributes.migrate
Read:
references/deprecations.md
10) Tooling and verification commands
Prefer whatever the repo already uses:
- (common) → run existing npm scripts
@wordpress/scripts - (common) → use for local WP + E2E
wp-env
Read:
references/tooling-and-testing.md
Verification
- Block appears in inserter and inserts successfully.
- Saving + reloading does not create “Invalid block”.
- Frontend output matches expectations (static: saved markup; dynamic: server output).
- Assets load where expected (editor vs frontend).
- Run the repo’s lint/build/tests that triage recommends.
Failure modes / debugging
If something fails, start here:
- (common failures + fastest checks)
references/debugging.md - (attributes not saving)
references/attributes-and-serialization.md - (invalid block after change)
references/deprecations.md
Escalation
If you’re uncertain about upstream behavior/version support, consult canonical docs first:
- WordPress Developer Resources (Block Editor Handbook, Theme Handbook, Plugin Handbook)
- Gutenberg repo docs for bleeding-edge behaviors