# Create Block Create Block is an **officially supported tool for scaffolding a WordPress plugin that registers a block**. It generates PHP, JS, CSS code, and everything you need to start the project. It also integrates a modern build setup with no configuration. _It is largely inspired by [create-react-app](https://create-react-app.dev/docs/getting-started). Major kudos to [@gaearon](https://github.com/gaearon), the whole Facebook team, and the React community._ > **Blocks are the fundamental elements of modern WordPress sites**. Introduced in [WordPress 5.0](https://wordpress.org/news/2018/12/bebo/), they allow [page and post builder-like functionality](https://wordpress.org/gutenberg/) to every up-to-date WordPress website. > _Learn more about the [Block API at the Gutenberg HandBook](https://developer.wordpress.org/block-editor/developers/block-api/block-registration/)._ ## Quick start ```bash $ npx @wordpress/create-block@latest todo-list $ cd todo-list $ npm start ``` The `slug` provided (`todo-list` in the example) defines the folder name for the scaffolded plugin and the internal block name. The WordPress plugin generated must [be installed manually](https://wordpress.org/documentation/article/manage-plugins/#manual-plugin-installation-1). _(requires `node` version `>=22.13.0`)_ > [Watch a video introduction to create-block on Learn.wordpress.org](https://learn.wordpress.org/tutorial/using-the-create-block-tool/) ## Usage The `create-block` command generates a project with PHP, JS, and CSS code for registering a block with a WordPress plugin. ```bash $ npx @wordpress/create-block@latest [options] [slug] ``` ![Demo](https://user-images.githubusercontent.com/699132/103872910-4de15f00-50cf-11eb-8c74-67ca91a8c1a4.gif) > The name for a block is a unique string that identifies a block. Block Names are structured as `namespace`/`slug`, where namespace is the name of your plugin or theme. > In most cases, we recommended pairing blocks with WordPress plugins rather than themes, because only using plugin ensures that all blocks still work when your theme changes. ### Interactive Mode When no `slug` is provided, the script will run in interactive mode and will start prompting for the input required (`slug`, title, namespace...) to scaffold the project. ### `namespace` By default, blocks are created with the `create-block` namespace. You should specify your own unique namespace: ```bash $ npx @wordpress/create-block@latest my-block --namespace=my-namespace ``` This creates `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 ### `slug` The use of `slug` is optional. When provided it triggers the _quick mode_, where this `slug` is used: - as the block slug (required for its identification) - as the output location (folder name) for scaffolded files - as the name of the WordPress plugin. The rest of the configuration is set to all default values unless overridden with some options listed below. ### `options` ```bash -V, --version output the version number -t, --template project template type name; allowed values: "standard" (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 the directory where the files will be scaffolded, defaults to the slug --namespace internal namespace for the block name --title display title for the block and the WordPress plugin --short-description short description for the block and the WordPress plugin --category category name for the block --wp-scripts enable integration with `@wordpress/scripts` package --no-wp-scripts disable integration with `@wordpress/scripts` package --wp-env enable integration with `@wordpress/env` package --typescript scaffold TypeScript source files, when the template supports it --no-typescript scaffold JavaScript source files, when the template supports it --textdomain text domain for internationalization -h, --help output usage information ``` #### `--template` This argument specifies an _external npm package_ as a template. ```bash $ npx @wordpress/create-block@latest --template my-template-package ``` This argument also allows to pick a _local directory_ as a template. ```bash $ npx @wordpress/create-block@latest --template ./path/to/template-directory ``` #### `--variant` With this argument, `create-block` will generate a [dynamic block](https://developer.wordpress.org/block-editor/getting-started/glossary/#dynamic-block) based on the built-in template. ```bash $ npx @wordpress/create-block@latest --variant dynamic ``` #### `--no-plugin` With this argument, the `create-block` package runs in _No plugin mode_ which only scaffolds block files into the current directory. ```bash $ npx @wordpress/create-block@latest --no-plugin ``` #### `--wp-env` With this argument, the `create-block` package will add to the generated plugin the configuration and the script to run [`wp-env` package](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-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. ```bash $ npx @wordpress/create-block@latest --wp-env ``` #### `--typescript` With this argument, the `create-block` package scaffolds the block source files in TypeScript. It also adds a `tsconfig.json` file, the `typescript` and `@types/react` packages, and a `typecheck` script to the generated plugin. The built-in `standard` template supports it, and external templates can opt in. ```bash $ npx @wordpress/create-block@latest --typescript ``` #### `--textdomain` With this argument, the `create-block` package will a generate a block with the provided text domain. If not specified, the block’s slug is used as the default text domain. ```bash $ npx @wordpress/create-block@latest --textdomain my-custom-domain ``` #### `--help` With this argument, the `create-block` package outputs usage information. ```bash $ npx @wordpress/create-block@latest --help ``` ## Available commands in the 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 the `scripts` package) to make your work easier. [Click here](https://github.com/WordPress/gutenberg/tree/HEAD/packages/scripts#available-scripts) for a full description of these commands. _Note: You don’t need to install or configure tools like [webpack](https://webpack.js.org), [Babel](https://babeljs.io) or [ESLint](https://eslint.org) yourself. They are preconfigured and hidden so that you can focus on coding._ For example, running the `start` script from inside the generated folder (`npm start`) would automatically start the build for development. ## External Project Templates [Click here](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/packages-create-block-external-template/) for information on External Project Templates ## Contributing to this package This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects. To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).

Code is Poetry.