A WordPress agency dev opens a Gutenberg tutorial from 2019 — separate index.js, editor.js, style.css, no block.json, manual wp_enqueue_script calls. They build the block, it works, and three months later WordPress 6.5 ships and the block looks wrong. The block API moved twice between 2019 and now. The modern workflow uses block.json, @wordpress/scripts, and the apiVersion: 3 register call. Half the friction in block development is using the wrong starting point.
What’s happening
WordPress 5.8 introduced block.json as the canonical block metadata file. WordPress 6.3 introduced apiVersion: 3, which moves the editor into an iframe and breaks any block that reaches up into the parent window. @wordpress/scripts is the official build tooling — webpack preconfigured for blocks, with hot reload, dependency extraction, and a CLI that scaffolds a block from a template.
The modern block development workflow:
- Scaffold with
@wordpress/create-block. block.jsondeclares everything — name, version, dependencies, supports, attributes, render path.- JavaScript lives under
src/and is built tobuild/by@wordpress/scripts start(dev) orbuild(production). - PHP registers the block by passing
block.jsontoregister_block_type().
The old workflow (separate files, manual enqueue, registerBlockType() in JS) still works, but every WordPress release adds a feature that’s only available via block.json. Skipping it leaves features on the table.
How to verify
Inspect an existing block’s setup:
ls wp-content/plugins/myplugin/blocks/example-block/
# expect: block.json, src/, build/, index.php
cat wp-content/plugins/myplugin/blocks/example-block/block.json | jq '.apiVersion, .name, .editorScript, .style'
apiVersion: 3 confirms it’s iframe-compatible. editorScript, style, and script should reference file:./build/index.js (or similar) — that’s how WordPress finds the built assets.
Run the build to confirm tooling is wired:
cd wp-content/plugins/myplugin
npm install
npm run build
ls -la blocks/example-block/build/
If build/index.js and build/index.asset.php exist after the build, the dependency extraction is working — that’s what tells WordPress which @wordpress/* packages the block needs.
What to do
Scaffold and ship a block with the modern workflow.
- Start in your plugin’s directory and scaffold:
cd wp-content/plugins/myplugin
npx @wordpress/create-block --template @wordpress/create-block-tutorial-template example-block
That creates blocks/example-block/ with everything wired up: package.json, block.json, src/, build scripts.
- Edit
block.jsonto declare what the block accepts:
{
"apiVersion": 3,
"name": "myplugin/example-block",
"version": "1.0.0",
"title": "Example Block",
"category": "widgets",
"icon": "smiley",
"description": "Example custom block",
"supports": {
"html": false,
"align": ["wide", "full"]
},
"attributes": {
"content": { "type": "string", "default": "" },
"url": { "type": "string", "default": "" }
},
"textdomain": "myplugin",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"render": "file:./render.php"
}
render is the path to a server-side render template — set it and save() in JS returns null. That’s the cleanest block shape: state in attributes, rendering in PHP, editor experience in JS. No serialization mismatches.
- The JavaScript
src/index.js:
import { registerBlockType } from '@wordpress/blocks';
import { useBlockProps, RichText, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, TextControl } from '@wordpress/components';
import metadata from './block.json';
registerBlockType(metadata.name, {
edit: ({ attributes, setAttributes }) => {
const props = useBlockProps();
return (
<div {...props}>
<InspectorControls>
<PanelBody title="Link">
<TextControl
label="URL"
value={attributes.url}
onChange={url => setAttributes({ url })}
/>
</PanelBody>
</InspectorControls>
<RichText
tagName="p"
value={attributes.content}
onChange={content => setAttributes({ content })}
placeholder="Type something..."
/>
</div>
);
},
save: () => null,
});
- The PHP
render.phprenders on the server, can include logic that JS can’t (database queries, current_user data, conditional output):
<?php
$content = $attributes['content'] ?? '';
$url = esc_url($attributes['url'] ?? '');
?>
<div <?php echo get_block_wrapper_attributes(); ?>>
<?php if ($url): ?>
<a href="<?php echo $url; ?>"><?php echo wp_kses_post($content); ?></a>
<?php else: ?>
<p><?php echo wp_kses_post($content); ?></p>
<?php endif; ?>
</div>
- Register the block from your main plugin file:
add_action('init', function() {
register_block_type(__DIR__ . '/blocks/example-block');
});
That single call reads block.json, enqueues the right assets, registers the server render — no manual wp_enqueue_script calls anywhere.
-
Development loop:
npm run startinwp-content/plugins/myplugin/blocks/example-block/. Editor hot-reloads on save. -
For shipping,
npm run buildproduces production bundles; the WordPress plugin contains thebuild/output but notnode_modules/.
For the block theme that wraps your blocks, see WordPress block themes from scratch. Stack Harbor’s Enterprise WordPress practice ships custom blocks with this workflow as standard. If a site has 12 hand-rolled Gutenberg blocks from 2019 that need an apiVersion bump, we can do the migration.