Posted in WordPress Beginner 26 min read

How to Create a Custom Gutenberg Block: A Beginner’s Guide to @wordpress/create-block

Build your first custom Gutenberg block with @wordpress/create-block: check Node.js, scaffold the plugin, tour every file, then add RichText and two sidebar settings.

If you want to know how to create a custom block for the WordPress block editor (Gutenberg) with code, the official route is the @wordpress/create-block tool. It scaffolds a plugin containing a working block, so you edit real files instead of starting from an empty folder[1][2]. In short, the steps are:

  1. Check that your Node.js version satisfies both create-block and @wordpress/scripts[3][4].
  2. Set up a local WordPress site, for example with wp-env, WordPress Studio, Local, XAMPP or MAMP[5].
  3. Run npx @wordpress/create-block@latest my-first-block[1][2].
  4. Activate the generated plugin and run npm start[2][6].
  5. Edit the files in src/my-first-block/, then run npm run build when you are done[6][7].

This beginner tutorial walks through each step, explains every file the tool generates, and then turns the “hello world” block into an editable note block with two sidebar settings.

Versions and untested code

Version numbers in this article reflect the npm registry, the Node.js release index and WordPress.org as of 22 November 2026, when create-block 5.2.0 was the latest release and WordPress.org offered WordPress 7.1.5[3][8]. The code examples are untested: they are based on the official documentation and the create-block 5.2.0 template source but have not been run, so check them against the versions you actually install.

Before you start: is a custom block the right tool?

This tutorial is the code route. Before you install a JavaScript toolchain, it is worth knowing the lighter options:

  • Block patterns are pre-configured groups of existing blocks. You register them with PHP files in a theme’s /patterns folder or with register_block_pattern(), without writing a custom block[9].
  • ACF Blocks let developers build blocks in PHP without JavaScript, but it is a feature of the paid ACF PRO plugin[10].
  • No-code plugins: WPBeginner’s custom block guide uses WPCode (block snippets need a paid plan) and the free Genesis Custom Blocks plugin, which avoids Node.js, npm and React[11].

If you want to learn how blocks really work, or you need full control over the editing experience, keep reading.

Prerequisites

You need a code editor, a terminal, basic JavaScript and HTML knowledge, Node.js with npm, and a local WordPress site. Node.js comes first, because it is where most beginner setups go wrong.

Check your Node.js version first

Open a terminal and run the two version checks the Block Editor Handbook uses[12]:

node -v
npm -v

The first command prints your Node.js version and the second prints your npm version. npm and npx are installed together with Node.js[5].

Compare your Node.js version with what the packages in this tutorial declare in their engines field:

Package Latest version (22 Nov 2026) Node.js requirement
@wordpress/create-block 5.2.0 >=22.13.0 [3]
@wordpress/scripts 37.2.0 ^22.22.2, ^24.15.0 or >=26.0.0 [4]
@wordpress/env (wp-env) 12.2.0 >=22.13.0 [13]
Node.js versions each package declares in its engines field.

create-block raised its minimum to Node.js 22.13.0 in version 5.0.0 as a breaking change[14]. The @wordpress/scripts range was introduced in version 36.0.0[15]. The two ranges do not match: a Node.js version between 22.13.0 and 22.22.1 passes create-block’s requirement but falls outside the range @wordpress/scripts declares, and installing a current Node.js LTS release (24.15 or later, or 26.x) avoids the gap[3][4].

The following table is our own reading of those two ranges, so you can check your node -v output quickly[3][4]:

Your Node.js version create-block 5.2.0 @wordpress/scripts 37.2.0
Below 22.13.0 Outside range Outside range
22.13.0 to 22.22.1 Inside range Outside range
22.22.2 or later 22.x Inside range Inside range
23.x Inside range Outside range
24.0.0 to 24.14.x Inside range Outside range
24.15.0 or later 24.x Inside range Inside range
25.x Inside range Outside range
26.0.0 or later Inside range Inside range
Which Node.js versions fall inside each package range (our own reading of the engines ranges).

On 10 and 11 November 2026, the Node.js release index listed v26.13.1, v24.22.3 and v22.23.5 as LTS releases, and each of them falls inside both ranges[16][3][4]. The @wordpress/scripts handbook page itself only says the package needs a Node.js version with long-term support (LTS) status[6], so the registry’s engines field is the more precise reference.

Install or update Node.js

The Block Editor Handbook recommends the Active LTS version of Node.js and strongly recommends a version manager such as nvm[5].

On macOS or Linux, the handbook installs nvm with nvm’s curl install script (copy the current command from the handbook’s Node.js development environment page), then installs an LTS release[12]:

nvm install --lts
node -v
npm -v

nvm install --lts installs a Node.js LTS release, and the two version commands confirm what you now have[12]. Check the printed version against the table above before you continue.

If your terminal says nvm is not found after installation on macOS with zsh, the handbook suggests creating the shell profile file, repeating the nvm install and restarting the terminal[12]:

touch ~/.zshrc

On Ubuntu or WSL, the equivalent file is ~/.bashrc[12]. On Windows, the handbook recommends the Node.js installer or Microsoft’s guide to nvm on Windows and WSL[12].

Choose a local WordPress environment

The handbook lists several local WordPress options, including wp-env (its recommendation), @wp-playground/cli, WordPress Studio, Local, XAMPP, MAMP and VVV[5]. Here is how the main ones compare for this tutorial:

Option What the sources say Good fit if
wp-env Official tool; needs Docker, Node.js and git; serves WordPress at http://localhost:8888 with username admin and password password by default [17] Your machine runs Docker comfortably
wp-env without Docker Experimental runtimes: wp-env start --runtime=playground (WebAssembly) and wp-env start --runtime=php (local PHP with SQLite, needs pdo_sqlite) [17] You want wp-env but cannot run Docker, and accept experimental features
WordPress Studio Free, open-source local development app for macOS, Windows and Linux [18] You prefer a desktop app
Local, XAMPP or MAMP Listed in the handbook as local environment options [5] You already use one of them
Local WordPress options for this tutorial.

If you choose wp-env on Windows, note that Docker Desktop (WSL 2 backend) lists 8GB of system RAM, hardware virtualization enabled in BIOS/UEFI, a 64-bit CPU with SLAT and WSL 2.1.5 or later as requirements[19]. Docker Desktop is free for personal use, education, non-commercial open source projects and small businesses (fewer than 250 employees and less than $10 million in revenue); larger organisations need a paid subscription[19].

To install wp-env globally, the package reference uses this command[17]:

npm -g i @wordpress/env

You will start it from the plugin folder in Step 3.

Step 1: Scaffold the block with create-block

Where you run the command depends on your local environment:

  • Local, Studio, XAMPP or MAMP: create the plugin directly in your site’s plugins folder.
  • wp-env: create the plugin in any working folder, because you start wp-env from inside the plugin folder[17].

For a site-based setup, move into the plugins folder first (replace the path with your own install)[20]:

cd /path/to/your/wordpress/install/wp-content/plugins

Then run the scaffold command and move into the new folder[1][2]:

npx @wordpress/create-block@latest my-first-block
cd my-first-block

npx runs the create-block package without a global install. If it asks to install the package, type y and press Enter[20]. The slug my-first-block becomes both the plugin folder name and the internal block name[2]. Because you gave a slug without --variant, the tool uses the first variant in its template, which is static[7].

If you run npx @wordpress/create-block@latest without a slug, it switches to interactive mode and asks for the slug, title, namespace and other values, including which variant to use[1][7].

A few options are useful even for beginners[1]:

  • --namespace sets the first part of the block name. The default is create-block, so this tutorial’s block is create-block/my-first-block.
  • --variant dynamic scaffolds a server-rendered block (covered later).
  • --wp-env adds an env npm script so you can run npm run env start[7][14].
  • --textdomain sets the translation text domain, which defaults to the slug.

This tutorial keeps the default namespace so the CSS class names below match what you see.

Step 2: Tour the generated files

Here is what the standard template generates. The tree is based on the create-block 5.2.0 template source[7]; npm’s dependency folder and lock file are not shown.

my-first-block/
├── my-first-block.php
├── package.json
├── readme.txt
├── .editorconfig
├── .gitignore
└── src/
    └── my-first-block/
        ├── block.json
        ├── index.js
        ├── edit.js
        ├── save.js
        ├── style.scss
        ├── editor.scss
        └── view.js

Notice that the block’s files live in src/my-first-block/, not directly in src/[7].

You may also see a build/ folder next to src/, for example if a build has already run. It holds the compiled block files under build/my-first-block/ and the generated blocks-manifest.php[6][7]. wp-scripts builds this folder from the block.json files and scripts it finds in src[6], so make your changes in src and do not edit the files in build/ by hand.

The plugin root

The template writes these five files to the plugin root[7]. The purposes in the right-hand column are a short general summary:

File Purpose
my-first-block.php Main plugin file: plugin header plus block registration
package.json npm scripts and development dependencies
readme.txt Plugin readme
.editorconfig Shared code editor formatting settings
.gitignore Files Git should ignore
Files create-block writes to the plugin root.

The main plugin file’s header defaults to Requires at least: 6.8, Requires PHP: 7.4 and version 0.1.0[7].

block.json

block.json is the canonical way to register a block type, and only name and title are required[21]. This is a simplified excerpt of the fields the template sets by default; your file also contains fields such as title and description[7]:

{
	"$schema": "https://schemas.wp.org/trunk/block.json",
	"apiVersion": 3,
	"name": "create-block/my-first-block",
	"version": "0.1.0",
	"category": "widgets",
	"icon": "smiley",
	"supports": {
		"html": false
	},
	"textdomain": "my-first-block",
	"editorScript": "file:./index.js",
	"editorStyle": "file:./index.css",
	"style": "file:./style-index.css",
	"viewScript": "file:./view.js"
}

What the important fields mean:

  • apiVersion: 3 means the block supports the iframed post editor; API version 3 was introduced in WordPress 6.3[21][22].
  • name uses the form namespace/block-name, with lowercase letters, numbers and dashes, and it must start with a letter[21].
  • category is widgets, one of the core block categories (text, media, design, widgets, theme and embed)[21][7].
  • icon: smiley is a Dashicon name[7].
  • editorScript and editorStyle load only in the editor, style loads in the editor and on the front end, and viewScript loads only on the front end[21].
  • file: paths are relative to the block.json file itself[21].

index.js, edit.js and save.js

index.js imports registerBlockType from @wordpress/blocks, the style.scss file, the Edit component, the save function and the metadata from block.json. It then calls registerBlockType( metadata.name, { edit: Edit, save } )[7]. In other words, block.json supplies the metadata and index.js attaches the JavaScript behaviour.

edit.js controls what you see in the editor. This simplified excerpt shows its structure (the generated file has extra comments and a slightly different string)[7]:

import { __ } from '@wordpress/i18n';
import { useBlockProps } from '@wordpress/block-editor';
import './editor.scss';

export default function Edit() {
	return (
		<p { ...useBlockProps() }>
			{ __( 'hello from the editor!', 'my-first-block' ) }
		</p>
	);
}
  • __() from @wordpress/i18n makes the string translatable, using the block’s text domain[7].
  • useBlockProps() adds the wrapper props a block needs, and it must be used on the block’s outermost element for API version 2 and later[23].

save.js returns the markup that is stored in the post. By default it returns <p { ...useBlockProps.save() }> with a “hello from the saved content!” string[7]. useBlockProps.save() is the save-side counterpart that static output must use[22].

style.scss, editor.scss and view.js

  • style.scss styles the .wp-block-create-block-my-first-block class on the front end and in the editor[7].
  • editor.scss adds a dotted red border that you only see in the editor[7].
  • view.js only logs a “Hello World!” message to the browser console on the front end[7]. If you do not need front-end JavaScript, delete view.js and remove the viewScript line from block.json, so no script is loaded for nothing. The note block in this tutorial does not need it, so Step 4 does exactly that.

The main PHP file and blocks-manifest.php

This is where the current scaffold differs most from older tutorials. When @wordpress/scripts is used (the default), the main plugin file registers blocks inside a function hooked to init by calling wp_register_block_types_from_metadata_collection()[7]. This is a simplified excerpt; the function name is our own illustration and your file will contain different naming and comments:

function my_first_block_init() {
	wp_register_block_types_from_metadata_collection(
		__DIR__ . '/build',
		__DIR__ . '/build/blocks-manifest.php'
	);
}
add_action( 'init', 'my_first_block_init' );
  • The first argument is the build folder that contains the compiled blocks, and the second is the generated manifest file[7].
  • wp_register_block_types_from_metadata_collection() was added in WordPress 6.8 and registers every block type in the manifest with a single call[6][24]. That is why the plugin header says Requires at least: 6.8[7].
  • blocks-manifest.php is generated by the --blocks-manifest flag of wp-scripts build and wp-scripts start, and it lets WordPress avoid reading each block.json file separately[6][24].

If your plugin must support WordPress versions older than 6.8, the dev note suggests a function_exists() check with a fallback to wp_register_block_metadata_collection() plus individual register_block_type() calls[24].

The npm scripts in package.json

Script Command or purpose When you use it
start wp-scripts start --blocks-manifest: watches the source files and rebuilds on every change [6] [7] While developing
build wp-scripts build --blocks-manifest: creates an optimized production build and exits [6] [7] Before sharing or deploying
format Runs the wp-scripts format command to format your code [7] Before committing
lint:css wp-scripts lint-style [7] To check your SCSS
lint:js wp-scripts lint-js [7] To check your JavaScript
packages-update Runs the wp-scripts packages-update command [7]; read the @wordpress/scripts reference before using it When updating WordPress packages
plugin-zip Creates a zip of the plugin, choosing files according to Plugin Handbook practices [6] [7] To install the plugin elsewhere
npm scripts in the generated package.json.

Run them with npm start or npm run <script>, for example npm run lint:js[2].

Step 3: Activate the plugin and run npm start

Start the build watcher from the plugin folder[25][6]:

npm start

This runs wp-scripts start --blocks-manifest, which compiles src/ into build/ and keeps watching for changes[6][7]. Leave this terminal open while you work.

If you use wp-env, open a second terminal in the same plugin folder and start WordPress[17]:

wp-env start

Then sign in at http://localhost:8888/wp-admin/ with the default admin / password credentials[17].

Next, open Plugins in your WordPress admin and activate My First Block. The block then appears in the editor’s inserter[2][20]. Create a new post, search the inserter for your block and add it. You should see the “hello from the editor” text with the dotted red editor border[7].

Step 4: Make the block editable with RichText

A block becomes useful when it stores data. Block data lives in attributes. Attributes without a source are saved in the block’s comment delimiter, while the html source extracts an element’s inner HTML and is typically used with the RichText component[26].

You will build a simple note block. The code in Steps 4 to 6 is our own illustration based on the RichText, Attributes and InspectorControls references; it is untested.

Declare the attribute in block.json

block.json is the canonical place for a block’s metadata[21], and the plugin registers the block on the server from the built block.json files through blocks-manifest.php[6][7]. This tutorial therefore declares attributes in block.json, so the server-side registration and the editor read the same definition. The RichText reference example declares its attribute in JavaScript inside registerBlockType() instead[27]; pick one place and do not declare the same attributes in both.

Make two changes:

  1. Delete the src/my-first-block/view.js file, because this block needs no front-end JavaScript.
  2. Replace the contents of src/my-first-block/block.json with the complete file below. It keeps every field the scaffold generated, in the same order, adds a top-level attributes field after "textdomain" and removes the "viewScript": "file:./view.js" line[7]. Keep the title and description values your own file already has if they differ.
{
	"$schema": "https://schemas.wp.org/trunk/block.json",
	"apiVersion": 3,
	"name": "create-block/my-first-block",
	"version": "0.1.0",
	"title": "My First Block",
	"category": "widgets",
	"icon": "smiley",
	"description": "Example block scaffolded with Create Block tool.",
	"example": {},
	"supports": {
		"html": false
	},
	"textdomain": "my-first-block",
	"attributes": {
		"content": {
			"type": "string",
			"source": "html",
			"selector": "p"
		}
	},
	"editorScript": "file:./index.js",
	"editorStyle": "file:./index.css",
	"style": "file:./style-index.css"
}
  • content is a string attribute whose value comes from the inner HTML of the block’s <p> element[27][26].
  • Watch the commas. JSON does not allow a comma after the last field of an object. viewScript used to be the last field, so once it is gone, "style": "file:./style-index.css" is the last line and must not end with a comma. If you edit the file by hand instead of pasting the whole thing, check that line.
  • Leave index.js exactly as generated. It already passes the metadata from block.json to registerBlockType()[7].

Update edit.js

Now replace src/my-first-block/edit.js:

import { __ } from '@wordpress/i18n';
import { useBlockProps, RichText } from '@wordpress/block-editor';
import './editor.scss';

export default function Edit( { attributes, setAttributes } ) {
	return (
		<div { ...useBlockProps() }>
			<RichText
				tagName="p"
				value={ attributes.content }
				onChange={ ( content ) => setAttributes( { content } ) }
				placeholder={ __( 'Write your note…', 'my-first-block' ) }
				allowedFormats={ [ 'core/bold', 'core/italic' ] }
			/>
		</div>
	);
}
  • Edit now receives attributes and setAttributes as props[25].
  • RichText renders an editable <p>; value shows the current content, onChange saves new content and placeholder appears while it is empty[27].
  • setAttributes( { content } ) updates the attribute, and the value must match the declared type, here a string[27][26].
  • allowedFormats limits the toolbar to bold and italic[27].
  • The outer <div> carries useBlockProps() because it is now the outermost element[23]. A wrapper is used so Step 5 can add a label next to the text.

Update save.js

Finally, replace src/my-first-block/save.js:

import { useBlockProps, RichText } from '@wordpress/block-editor';

export default function save( { attributes } ) {
	return (
		<div { ...useBlockProps.save() }>
			<RichText.Content tagName="p" value={ attributes.content } />
		</div>
	);
}
  • RichText.Content outputs the saved rich text in a <p> tag[27].
  • Do not print attributes.content directly. If formatting tags appear escaped on the front end, the save function is outputting the value directly instead of using RichText.Content[27].
  • The wrapper uses useBlockProps.save(), as static save output requires[22].

With npm start still running, the build updates automatically[6]. Reload the editor. If the block you inserted in Step 3 now shows an error, read the section on “unexpected or invalid content” below.

Step 5: Add sidebar settings with InspectorControls

Next, add two settings to the block settings sidebar: a toggle that shows or hides a label above the note, and a text field for the label itself, which defaults to “Note”. InspectorControls renders its children in the block settings sidebar, and it is used with controls from @wordpress/components such as PanelBody, ToggleControl and TextControl[28][25].

Add two attributes to block.json

Extend the attributes field in src/my-first-block/block.json. The complete file now looks like this:

{
	"$schema": "https://schemas.wp.org/trunk/block.json",
	"apiVersion": 3,
	"name": "create-block/my-first-block",
	"version": "0.1.0",
	"title": "My First Block",
	"category": "widgets",
	"icon": "smiley",
	"description": "Example block scaffolded with Create Block tool.",
	"example": {},
	"supports": {
		"html": false
	},
	"textdomain": "my-first-block",
	"attributes": {
		"content": {
			"type": "string",
			"source": "html",
			"selector": "p"
		},
		"showLabel": {
			"type": "boolean",
			"default": true
		},
		"label": {
			"type": "string",
			"default": "Note"
		}
	},
	"editorScript": "file:./index.js",
	"editorStyle": "file:./index.css",
	"style": "file:./style-index.css"
}

Each new attribute needs a comma after the closing brace of the one before it, and the last one, label, has none.

showLabel and label have no source, so their values are saved in the block’s comment delimiter rather than read from the HTML[26].

The label is an attribute, not a translated string, for a reason. A static block’s saved HTML is stored in the post, and when the post is opened again the editor compares that stored HTML with what save returns now; a mismatch causes a validation error[29]. So save should build its markup only from the attributes it receives. A string translated with __() inside save could come out differently for an editor who uses another language, and then the markup would no longer match. Translated strings belong in edit.js, where they only affect the editing interface.

Install the components package

PanelBody, ToggleControl and TextControl come from @wordpress/components. If that package is not listed in your package.json, add it from the plugin folder:

npm install @wordpress/components --save

This records @wordpress/components as a dependency of your plugin, so npm run lint:js[7] does not flag the import as a package your project never declared.

Update edit.js

Replace edit.js again:

import { __ } from '@wordpress/i18n';
import {
	useBlockProps,
	RichText,
	InspectorControls,
} from '@wordpress/block-editor';
import { PanelBody, TextControl, ToggleControl } from '@wordpress/components';
import './editor.scss';

export default function Edit( { attributes, setAttributes } ) {
	const { content, showLabel, label } = attributes;

	return (
		<>
			<InspectorControls>
				<PanelBody title={ __( 'Settings', 'my-first-block' ) }>
					<ToggleControl
						label={ __( 'Show label', 'my-first-block' ) }
						checked={ showLabel }
						onChange={ ( value ) =>
							setAttributes( { showLabel: value } )
						}
					/>
					{ showLabel && (
						<TextControl
							label={ __( 'Label text', 'my-first-block' ) }
							value={ label }
							onChange={ ( value ) =>
								setAttributes( { label: value } )
							}
						/>
					) }
				</PanelBody>
			</InspectorControls>
			<div { ...useBlockProps() }>
				{ showLabel && label && <strong>{ label }</strong> }
				<RichText
					tagName="p"
					value={ content }
					onChange={ ( newContent ) =>
						setAttributes( { content: newContent } )
					}
					placeholder={ __( 'Write your note…', 'my-first-block' ) }
					allowedFormats={ [ 'core/bold', 'core/italic' ] }
				/>
			</div>
		</>
	);
}
  • The empty <> fragment lets the component return the sidebar controls and the block markup together.
  • InspectorControls places the PanelBody in the settings sidebar instead of in the content[28].
  • ToggleControl shows a switch; checked reflects the attribute and onChange stores the new true or false value with setAttributes[25][26].
  • TextControl is a text field; it shows the current label and stores whatever you type with setAttributes[25][28]. It only appears while the toggle is on.
  • { showLabel && label && ... } is standard React conditional rendering: the label renders only when the toggle is on and the label text is not empty.
  • The sidebar labels (“Settings”, “Show label”, “Label text”) use __() because they are part of the editing interface, not of the saved content.

Update save.js

Update save.js so the saved markup matches:

import { useBlockProps, RichText } from '@wordpress/block-editor';

export default function save( { attributes } ) {
	const { content, showLabel, label } = attributes;

	return (
		<div { ...useBlockProps.save() }>
			{ showLabel && label && <strong>{ label }</strong> }
			<RichText.Content tagName="p" value={ content } />
		</div>
	);
}

The save function mirrors the editor markup: the same wrapper, the same condition for the label and the rich text. It reads everything from attributes and imports nothing from @wordpress/i18n, so its output depends only on the data stored with the block. Keep these two files in step: if you change the condition or the markup in one, change it in the other.

Step 6: Style the block

The generated style.scss already targets the block’s class, .wp-block-create-block-my-first-block, and its styles apply in the editor and on the front end[7]. Replace its contents with this illustration:

.wp-block-create-block-my-first-block {
	border-left: 4px solid currentcolor;
	padding: 0.75em 1em;

	strong {
		display: block;
		margin-bottom: 0.25em;
	}
}
  • The left border and padding give the note a callout look, using the current text colour so it adapts to your theme.
  • strong is the label; display: block puts it on its own line.

Because editor.scss adds a dotted red border in the editor only[7], you may want to delete that rule now so the editor preview matches the front end.

Why your block shows “unexpected or invalid content”

After Step 4 or Step 5, a block you inserted earlier may show a message that it contains “unexpected or invalid content”. This is expected behaviour for static blocks, not a broken install.

A static block’s save function returns HTML that is stored in post_content, wrapped in block delimiter comments[29]. When you change a static block’s save markup after content already exists, the editor’s validation compares the stored HTML with the new save output, and the mismatch causes a validation error[29][30].

While you are learning, the practical fix is simple: delete the old block and insert a fresh one. On a real site with published content, think carefully before changing save.js, or consider a dynamic block, because dynamic blocks skip markup validation[29].

Static vs dynamic blocks

The block you built is static. create-block can also scaffold a dynamic block, which is rendered by PHP on the server[1][29]:

npx @wordpress/create-block@latest my-dynamic-block --variant dynamic

This creates a render.php file instead of save.js[25][1][7]. The generated block.json gains a render field pointing at file:./render.php[7], and the build and start scripts gain --webpack-copy-php[7], which copies all PHP files from src to the build folder[6].

This simplified excerpt shows the structure of the generated render.php (the exact string in your file will differ)[7]:

<p <?php echo get_block_wrapper_attributes(); ?>>
	<?php esc_html_e( 'hello from a dynamic block!', 'my-dynamic-block' ); ?>
</p>
  • The <p> tag gets its wrapper attributes from get_block_wrapper_attributes()[7].
  • The string is translatable and escaped on output[7].
  • render.php receives $attributes, $content and $block, so you can use the block’s saved attributes when rendering[21][29].
Static block Dynamic block
Scaffold Default, or --variant static [7] --variant dynamic [1]
Front-end markup comes from save.js [7] render.php [7]
Stored in the post Full HTML inside block delimiter comments [29] Only the delimiter and attributes [29]
Markup validation Yes, so changing save can trigger "invalid content" errors [29] Skipped [29]
Good for Content that stays as written Content that should change without editing the post, such as Latest Posts, or markup changes that should appear site-wide immediately [29]
Static vs dynamic blocks at a glance.

WordPress 7.1 always iframes the editor

Block API version 3 enables the iframed post editor, and blocks with API version 3 must work inside an iframe[21][22]. In WordPress 7.0, the post editor decided whether to use the iframe based on the API versions of the blocks inserted in the post, and dropped the iframe if any of them was below version 3[22][31]. Starting in WordPress 7.1, the post editor is always iframed, regardless of theme type or block API versions[22][32].

For your own code, this means[32]:

  • Do not use the global document or window to reach the editor canvas.
  • Use an element’s ownerDocument or defaultView instead, and useRefEffect for event listeners.

The scaffolded block already uses apiVersion: 3[7]. Some tutorials still use API version 2; Kinsta’s block tutorial is one example[30].

Troubleshooting

The block does not appear in the inserter.

  • Check that the plugin is active on the Plugins page[2][20].
  • Check that npm start or npm run build has run. The plugin registers blocks from the build folder and its manifest, so nothing registers until a build exists[6][7].
  • Check your WordPress version. The scaffold requires WordPress 6.8 because of wp_register_block_types_from_metadata_collection()[24][7].

nvm: command not found after installing nvm. On macOS with zsh, run touch ~/.zshrc, repeat the nvm install and restart the terminal; on Ubuntu or WSL, use ~/.bashrc[12].

Node.js version complaints. Compare node -v with the compatibility table in the prerequisites. Remember that create-block accepts 22.13.0 while @wordpress/scripts expects at least 22.22.2 on the 22.x line[3][4].

npm start or npm run build complains about block.json after you edit it. The file is probably no longer valid JSON. Look for a comma after the last field of an object, such as a leftover comma on the style line after you removed viewScript, or a missing comma between two fields. Compare your file with the complete block.json in Step 4 or Step 5.

Your edits do not show up. Edit the files in src/, never in build/. wp-scripts finds the block.json files in src and builds them into matching folders under build[6]. Make sure npm start is still running so it rebuilds on every change[6].

Bold or italic tags appear as text on the front end. The save function is printing the attribute value directly; use RichText.Content instead[27].

Code that worked in older tutorials misbehaves in the editor. Look for uses of the global document or window, which do not reach the iframed canvas[32].

Another tutorial’s main plugin file uses register_block_type(). That is not necessarily wrong, but it is not what the current scaffold generates. The Learn WordPress “Scaffolding a new block” lesson shows register_block_type() and @wordpress/scripts ^26.12.0[20], and Kinsta’s tutorial uses API version 2 and register_block_type()[30]. The current default uses wp_register_block_types_from_metadata_collection(); only the --no-wp-scripts option uses register_block_type( __DIR__ . '/build/<slug>' )[7].

Docker will not run on your Windows machine. Check Docker Desktop’s Windows requirements listed in the prerequisites[19]. If they are a problem, try wp-env’s experimental --runtime=playground or --runtime=php options, or one of the other local environments the handbook lists, such as Studio, Local, XAMPP or MAMP[5][17]. Check each tool’s own system requirements before you install it.

Build and package the plugin

When the block works the way you want, stop npm start and create a production build[6]:

npm run build

This runs wp-scripts build --blocks-manifest, which writes optimized files to build/ and regenerates blocks-manifest.php[6][7].

To create an installable zip file, run[6]:

npm run plugin-zip

plugin-zip chooses which files go into the zip according to Plugin Handbook practices[6]. You can then install the zip on another WordPress site by uploading it from the Plugins screen.

Before you share the plugin, open readme.txt. The scaffold’s “Tested up to” value is 6.8, which lags the current 7.1.x release, so update it once you have checked the block on the WordPress version you support[7][8].

Next steps

Once your note block works, these are good next exercises:

  1. Scaffold a dynamic block with --variant dynamic and print an attribute from $attributes in render.php[1][29].
  2. Add a dropdown setting. Besides ToggleControl and TextControl, InspectorControls works with SelectControl from @wordpress/components, which suits a choice between a few fixed options[28].
  3. Work through the official tutorial. The Block Editor Handbook’s Build your first block tutorial builds a Copyright Date block with --variant=dynamic, attributes and InspectorControls[25].
  4. Use your own namespace on your next block with --namespace, so its name is not create-block/...[1].
  5. Re-check versions after WordPress 7.2, which the WordPress roadmap projects for 10 December 2026, describing projected dates as rough planning only[33].

Frequently asked questions

What Node.js version do I need for @wordpress/create-block?

create-block 5.2.0 declares Node.js 22.13.0 or later, while @wordpress/scripts 37.2.0 declares ^22.22.2, ^24.15.0 or >=26.0.0. A current Node.js LTS release (24.15 or later, or 26.x) satisfies both[3][4].

Can I create a custom block without JavaScript?

Partly. ACF Blocks let you build blocks in PHP without JavaScript, but they are a feature of the paid ACF PRO plugin[10]. If you only need a reusable group of existing blocks, a block pattern needs no custom block at all[9].

What is the difference between a static and a dynamic block?

A static block gets its front-end markup from save.js, and the full HTML is stored in the post. A dynamic block uses render.php, stores only the block delimiter and attributes, and skips markup validation, so its output can change without editing the post[7][29].

Which WordPress version does the generated plugin need?

WordPress 6.8 or later. The scaffold registers blocks with wp_register_block_types_from_metadata_collection(), which was added in WordPress 6.8, so the plugin header says Requires at least: 6.8[7][24].

Where do I edit my block’s code?

In src/my-first-block/. wp-scripts builds the files in build/ from src, so edit the source files and let npm start or npm run build regenerate the rest[6][7].

Conclusion

To create a custom block with code, start with the Node.js check, because create-block 5.2.0 and @wordpress/scripts 37.2.0 declare different Node.js ranges[3][4]. Then pick a local WordPress setup that suits your machine and scaffold with npx @wordpress/create-block@latest. The current scaffold puts your block in src/<slug>/, uses apiVersion: 3 and registers it through blocks-manifest.php, which needs WordPress 6.8 or later[7][24].

From there, the pattern repeats for every Gutenberg block you build: declare attributes in block.json, edit them in edit.js, output them in save.js or render.php, and rebuild. Remember that the example code here is untested, so compare it with the official references for the versions you install.

For more step-by-step guides like this one, browse the Veducator WordPress and web development tutorials.

Before you go

Key takeaways

  • Check node -v first: create-block 5.2.0 and @wordpress/scripts 37.2.0 accept different Node.js ranges, so pick a version inside both.
  • Scaffold with npx @wordpress/create-block@latest my-first-block, activate the plugin and run npm start.
  • Edit the files in src/my-first-block/, never in build/.
  • Declare attributes in block.json and keep save.js dependent only on attributes, or the block can show "unexpected or invalid content".
  • Use --variant dynamic and render.php when the front-end output should change without editing the post.
  • Finish with npm run build and npm run plugin-zip to get an installable plugin.

Sources

  1. @wordpress/create-block package reference, WordPress Developer Resources.
  2. Get started with create-block, WordPress Developer Resources.
  3. npm registry metadata: @wordpress/create-block (latest), npm registry.
  4. npm registry metadata: @wordpress/scripts (latest), npm registry.
  5. Block Development Environment, WordPress Developer Resources.
  6. @wordpress/scripts package reference, WordPress Developer Resources.
  7. @wordpress/create-block 5.2.0 published package source (templates), npm registry / WordPress contributors.
  8. WordPress.org core version-check API, WordPress.org.
  9. Block Patterns (Theme Handbook), WordPress Developer Resources.
  10. ACF Blocks, Advanced Custom Fields (WP Engine).
  11. How to Create a Custom Gutenberg Block in WordPress, WPBeginner.
  12. Node.js development environment, WordPress Developer Resources.
  13. npm registry metadata: @wordpress/env (latest), npm registry.
  14. @wordpress/create-block CHANGELOG, WordPress/gutenberg on GitHub.
  15. @wordpress/scripts CHANGELOG, WordPress/gutenberg on GitHub.
  16. Node.js release index, Node.js project.
  17. @wordpress/env (wp-env) package reference, WordPress Developer Resources.
  18. WordPress Studio, WordPress.com (Automattic).
  19. Install Docker Desktop on Windows, Docker Docs.
  20. Scaffolding a new block (Beginner WordPress Developer course), Learn WordPress.
  21. Metadata in block.json, WordPress Developer Resources.
  22. API Versions, WordPress Developer Resources.
  23. @wordpress/block-editor package reference, WordPress Developer Resources.
  24. More efficient block type registration in 6.8, Make WordPress Core (Felix Arntz).
  25. Tutorial: Build your first block, WordPress Developer Resources (Block Editor Handbook).
  26. Attributes, WordPress Developer Resources.
  27. RichText Reference, WordPress Developer Resources.
  28. InspectorControls README (Gutenberg repository), WordPress/gutenberg on GitHub.
  29. Static or Dynamic rendering of a block, WordPress Developer Resources.
  30. Building Custom Gutenberg Blocks: The Definitive Block Development Tutorial, Kinsta.
  31. Iframed Editor Changes in WordPress 7.0, Make WordPress Core (Ella Van Durpe).
  32. Iframed Editor Changes in WordPress 7.1, Make WordPress Core (Aki Hamano).
  33. WordPress Roadmap, WordPress.org.

Was this article helpful?

Written by Alpa Sharma

Writes Veducator's WordPress tutorials on themes, plugins and hooks.

Comments

Leave a reply

Your email address will not be published. Required fields are marked *