@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
Requires Node.js >= 20.10.0 and npm >= 10.2.3
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:Terminal
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:
Access WordPress
Open http://localhost:8888
- 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
Starts the build for development with watch mode.Automatically rebuilds when you make changes to the code.
npm run build
npm run build
Builds the code for production.Generates optimized assets in the
build folder.npm run format
npm run format
Formats files using Prettier.
npm run lint:css
npm run lint:css
Lints CSS files using Stylelint.
npm run lint:js
npm run lint:js
Lints JavaScript files using ESLint.
npm run packages-update
npm run packages-update
Updates WordPress packages to the latest versions.
npm run plugin-zip
npm run plugin-zip
Creates a ZIP file of the plugin.Useful for distributing your plugin.
You don’t need to configure webpack, Babel, or ESLint yourself. They’re preconfigured and hidden so you can focus on coding.
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
Edit block code
Modify files in the
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
Understanding block.json
Theblock.json file contains your block’s metadata:
src/block.json
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
Choose descriptive, semantic names:Good:
testimonialpricing-tablefeature-grid
block1custom-blockmy-block
Keep namespace consistent
Keep namespace consistent
Use your company or project name as the namespace:All your blocks should use the same namespace (e.g.,
acme/testimonial, acme/pricing-table).Pair blocks with plugins, not themes
Pair blocks with plugins, not themes
Blocks should be part of plugins, not themes. This ensures blocks continue working when users change themes.
Use wp-env for local testing
Use wp-env for local testing
Add
--wp-env flag to quickly test your block:Keep dependencies updated
Keep dependencies updated
Regularly update WordPress packages:
Troubleshooting
Node version error
Node version error
Error:
create-block requires Node.js 20.10.0 or higherSolution: Update Node.js:Block not appearing in editor
Block not appearing in editor
Checklist:
- 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
Solution: Clean install dependencies:
Styles not loading
Styles not loading
Check:
- 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
Learn about block development concepts and APIs
Block API Reference
Explore block registration and block.json options
@wordpress/scripts
Learn about available build commands and options
@wordpress/env
Set up a local WordPress environment for testing
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