create-block tool.
Registering blocks in plugins ensures they stay accessible even when users switch themes.
Plugin file structure
Main plugin file (plugin.php)
The main PHP file registers the block on the server using the register_block_type() function:
Package configuration (package.json)
The package.json file configures the Node.js project, defining dependencies and build scripts:
Source folder (src/)
The src folder contains raw, uncompiled code that gets processed during the build.
block.json
Defines the block’s metadata, streamlining registration across client and server:
index.js
The entry point for JavaScript loaded in the Block Editor:
edit.js
The React component that renders the block’s editing interface:
save.js
Returns the static HTML markup saved to the database:
style.scss
Styles loaded in both the Block Editor and front end:
editor.scss
Additional styles applied only in the Block Editor:
render.php (optional)
Defines server-side rendering for dynamic blocks:
view.js (optional)
JavaScript loaded on the front end when the block is displayed:
Build folder (build/)
The build folder contains compiled and optimized code generated by wp-scripts:
1
Source compilation
Modern JavaScript is transpiled to be compatible with wider browser support
2
Asset bundling
Files are minified and bundled for efficient loading
3
WordPress integration
WordPress enqueues files from the
build folderBuild process
Run these commands to build your block:Next steps
Block metadata
Learn about block.json properties
Block registration
Understand how blocks are registered