Skip to main content
When developing custom blocks for WordPress, it’s best practice to register them within plugins rather than themes. This guide details the file structure as produced by the 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:
Key properties in block.json:
  • editorScript: Path to bundled index.js (built from src/index.js)
  • style: Path to bundled style-index.css (built from src/style.scss)
  • editorStyle: Path to bundled index.css (built from src/editor.scss)
  • render: Path to render.php for dynamic blocks

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 folder
Always point register_block_type() to the build directory, not src.

Build process

Run these commands to build your block:
For development with automatic rebuilding:

Next steps

Block metadata

Learn about block.json properties

Block registration

Understand how blocks are registered