@wordpress/create-block is the official tool for scaffolding WordPress plugins that register blocks. It generates PHP, JS, and CSS code with a modern build setup requiring zero configuration.
Quick Start
Generate a new block plugin
todo-list.Navigate to the plugin directory
Start development
Install the plugin
wp-content/plugins/ directory and activate it from the WordPress admin.Usage
Basic Command
slug defines:
- Block slug (for identification)
- Output folder name
- WordPress plugin name
Interactive Mode
When you run the command without a slug, it prompts you for input:Options
—template
Specify an external npm package or local directory as a template.—variant
Generate a dynamic block variant:—namespace
Specify a custom namespace for your block:my-namespace/my-block instead of create-block/my-block.
Update the namespace in:
block.json- thenameproperty
—no-plugin
Scaffold only block files without the plugin wrapper:—target-dir
Specify the output directory:—title
Set the display title for the block and plugin:—short-description
Set the short description:—category
Set the block category:textmediadesignwidgetsthemeembed
—wp-scripts
Enable or disable integration with@wordpress/scripts:
—wp-env
Add@wordpress/env configuration to the generated plugin:
Generate block with wp-env
Start local environment
Access WordPress
- Username:
admin - Password:
password
—textdomain
Set a custom text domain for internationalization:—version
Display version information:—help
Display usage information:Complete Options Reference
Generated Project Structure
When you runcreate-block, it generates this structure:
Available Scripts in Generated Project
The generated plugin includes these npm scripts:npm start
npm start
npm run build
npm run build
build folder.npm run format
npm run format
npm run lint:css
npm run lint:css
npm run lint:js
npm run lint:js
npm run packages-update
npm run packages-update
npm run plugin-zip
npm run plugin-zip
Examples
Create a Block with Custom Namespace
- Block name:
acme/testimonial - Plugin folder:
testimonial
Create a Dynamic Block
Create Multiple Blocks (No Plugin Mode)
Add a new block to an existing plugin:Create Block with Local Development Environment
Create Block from Custom Template
Block Development Workflow
Generate the block
Start development server
Edit block code
src directory:block.json- block metadataedit.js- editor interfacesave.js- front-end outputstyle.scss- front-end and editor styleseditor.scss- editor-only styles
Test in WordPress
- Copy the plugin folder to
wp-content/plugins/ - Activate the plugin in WordPress admin
- Add the block to a post or page
Build for production
Create distribution package
Understanding block.json
Theblock.json file contains your block’s metadata:
name- unique block identifier (namespace/slug)title- display name in the editorcategory- where the block appears in the insertericon- Dashicon or custom SVGeditorScript- JavaScript for the editoreditorStyle- CSS for the editor onlystyle- CSS for both editor and front-end
Block Templates
Create Block supports custom templates for different use cases.Built-in Templates
External Templates
You can use external npm packages as templates:Tips and Best Practices
Use semantic block names
Use semantic block names
testimonialpricing-tablefeature-grid
block1custom-blockmy-block
Keep namespace consistent
Keep namespace consistent
acme/testimonial, acme/pricing-table).Pair blocks with plugins, not themes
Pair blocks with plugins, not themes
Use wp-env for local testing
Use wp-env for local testing
--wp-env flag to quickly test your block:Keep dependencies updated
Keep dependencies updated
Troubleshooting
Node version error
Node version error
create-block requires Node.js 20.10.0 or higherSolution: Update Node.js:Block not appearing in editor
Block not appearing in editor
- Is the plugin activated?
- Did you run
npm run buildornpm start? - Are there errors in the browser console?
- Is the block name in
block.jsonunique?
Build errors
Build errors
Styles not loading
Styles not loading
- Are style imports in
index.js? - Did the build complete successfully?
- Are the CSS files in the
buildfolder? - Is the plugin enqueuing assets correctly?
Next Steps
After creating your block:Block Editor Handbook
Block API Reference
@wordpress/scripts
@wordpress/env
Package Information
- Version: 4.83.0
- Node.js: >= 20.10.0
- npm: >= 10.2.3
- License: GPL-2.0-or-later
- Binary:
wp-create-block
Related Packages
- @wordpress/scripts - Build and test scripts
- @wordpress/env - Local WordPress environment
- @wordpress/block-editor - Block editor components