@wordpress/create-block package is an officially supported tool to scaffold the structure of files needed to create and register a block.
It generates all the necessary code to start a project and integrates a modern JavaScript build setup (using wp-scripts) with no configuration required. The package is designed to help developers quickly set up a block development environment following WordPress best practices.
Blocks are the fundamental elements of modern WordPress sites. Introduced in WordPress 5.0, they allow page and post builder-like functionality to every up-to-date WordPress website.
Quick Start
Start by ensuring you have Node.js and
npm installed on your computer. Review the Node.js development environment guide if not.The WordPress plugin generated must be installed manually.
You can use
wp-env from inside the generated plugin folder to create a local WordPress development environment with your new block plugin installed and activated.If you have your own local WordPress development environment already set up, copy the plugin folder to the
wp-content/plugins/ directory.Basic Usage
Thecreate-block package assumes you will use modern JavaScript (ESNext and JSX) to build your block. This requires a build step to compile the code into a format that browsers can understand. Luckily, the wp-scripts package handles this process for you.
When create-block scaffolds the block, it installs wp-scripts and adds the most common scripts to the block’s package.json file:
Development Workflow
The two scripts you will use most often arestart and build:
npm start- Starts a development server and automatically rebuilds the block whenever any code change is detectednpm run build- Optimizes your code and makes it production-ready
Command Options
Thecreate-block command provides several options for customization:
Available Options
-V, --version- Output the version number-t, --template <name>- Project template type name; allowed values: “static” (default), “es5”, the name of an external npm package, or the path to a local directory--variant- Choose a block variant as defined by the template--no-plugin- Scaffold block files only--target-dir <directory>- The directory where the files will be scaffolded, defaults to the slug--namespace <value>- Internal namespace for the block name--title <value>- Display title for the block and the WordPress plugin--short-description <value>- Short description for the block and the WordPress plugin--category <name>- Category name for the block--wp-scripts- Enable integration with@wordpress/scriptspackage--no-wp-scripts- Disable integration with@wordpress/scriptspackage--wp-env- Enable integration with@wordpress/envpackage--textdomain <value>- Text domain for internationalization-h, --help- Output usage information
Interactive Mode
For developers who prefer a more guided experience, thecreate-block package provides an interactive mode. Instead of manually specifying all options upfront, this mode will prompt you for inputs step-by-step.
To use this mode, run the command:
Advanced Usage
Custom Namespace
By default, blocks are created with thecreate-block namespace. You should specify your own unique namespace:
my-namespace/my-block instead of create-block/my-block.
If you’ve already created a block, update the namespace in block.json - the name property.
Dynamic Block Variant
With this argument,create-block will generate a dynamic block based on the built-in template:
No Plugin Mode
With this argument, thecreate-block package runs in No plugin mode which only scaffolds block files into the current directory:
With wp-env Integration
With this argument, thecreate-block package will add to the generated plugin the configuration and the script to run wp-env within the plugin. This will allow you to easily set up a local WordPress environment (via Docker) for building and testing the generated plugin:
Using External Templates
Thecreate-block package also supports the use of templates, enabling you to create blocks based on predefined configurations and structures.
This argument specifies an external npm package as a template:
create-block package knows where to find them. Learn more in the External Project Templates guide.
Quick Start with Options
If you’re already familiar with thecreate-block options and want a more streamlined setup, you can use quick start mode. This allows you to pass specific options directly in the command line:
Block Name Structure
The name for a block is a unique string that identifies a block. Block Names are structured asnamespace/slug, where namespace is the name of your plugin or theme.
In most cases, we recommend pairing blocks with WordPress plugins rather than themes, because only using plugin ensures that all blocks still work when your theme changes.
Available Commands in Scaffolded Project
The plugin folder created when executing this command is a node package with a modern build setup that requires no configuration. A set of scripts is available from inside that folder (provided by thescripts package) to make your work easier:
npm start- Starts the build for developmentnpm run build- Builds the code for productionnpm run format- Formats filesnpm run lint:css- Lints CSS filesnpm run lint:js- Lints JavaScript filesnpm run packages-update- Updates WordPress packages to the latest versionnpm run plugin-zip- Creates a zip file for a WordPress plugin