Prerequisites
Before starting, ensure you have Node.js and npm installed on your computer. Review the installation guide if you haven’t set up your development environment yet.
Scaffold the block plugin
Navigate to your plugins directory
If you have a local WordPress development environment, navigate to the
plugins/ folder using the terminal:You can use
create-block to scaffold a block anywhere and then use wp-env inside the generated plugin folder. This creates a local WordPress development environment with your new block plugin installed and activated.Run the create-block command
Use the The
@wordpress/create-block package with the tutorial template to scaffold the complete plugin:slug provided (copyright-date-block) defines:- The folder name for the scaffolded plugin
- The internal block name
The
create-block package installs wp-scripts and adds the most common scripts to the block’s package.json file automatically.Start development
With the plugin scaffolded and activated, you can start developing:npm start command:
- Starts a development server
- Watches for changes in the block’s code
- Automatically rebuilds the block whenever modifications are made
Test with wp-env
The scaffolded plugin includes configuration forwp-env, making it easy to test your block:
Ensure Docker is running
You must have Docker installed and running on your machine.
Start the environment
Run the following command from your plugin directory:Once the script finishes, you can access the local environment at:
http://localhost:8888Project structure
Here’s whatcreate-block generates for you:
Key files explained
block.json
Theblock.json file contains all metadata for your block:
edit.js
Defines how your block appears in the editor:save.js
Defines how your block is saved to the database:Common npm scripts
The scaffolded plugin includes these useful scripts:Customize your block
Now that you have a working block, try customizing it:- Change the icon - Modify the
iconproperty inblock.json - Add styling - Edit
editor.scssfor editor styles orstyle.scssfor frontend styles - Add attributes - Define custom attributes in
block.jsonto make your block configurable - Add controls - Use WordPress components like
TextControlorColorPickerinedit.js
Next steps
Block Editor Handbook
Explore comprehensive tutorials, API references, and guides.
Block development examples
Browse example blocks demonstrating different features and techniques.
Core blocks source
Study how WordPress core blocks are implemented.
WordPress Developer Blog
Stay updated with the latest WordPress development articles.