The introduction of the Gutenberg Block Editor fundamentally transformed WordPress into a modern React.js single-page application (SPA). While legacy shortcodes relied on clunky PHP text parsing, modern enterprise WordPress engineering demands creating bespoke Custom Gutenberg Blocks. In this class, you will learn the modern WordPress 6.x standard for building blocks using React JSX, modern build tools (@wordpress/scripts), and the block.json metadata specification.
Figure 38.1: Full Gutenberg Block Engineering Pipeline
The official, recommended way to scaffold a modern Gutenberg block plugin is using the WordPress core team's official Node.js generator. In your terminal, navigate to /wp-content/plugins/ and execute:
# Scaffolding a custom block plugin via npm
npx @wordpress/create-block veewom-cta-box --variant=static
This single command configures a complete TypeScript/Babel/Webpack build pipeline (via @wordpress/scripts), installs NPM dependencies, and creates the following production architecture:
/veewom-cta-box/
├── block.json # Block Metadata (API v3)
├── package.json # Node build scripts
├── src/
│ ├── block.json
│ ├── edit.js # React Component rendered inside wp-admin
│ ├── save.js # HTML rendered on public frontend
│ ├── index.js # Block Registration
│ ├── style.scss # Frontend + Backend styles
│ └── editor.scss # Backend Editor-only styles
└── build/ # Compiled production bundle
In WordPress 6.x, block.json is the absolute single source of truth for your block's attributes and capabilities:
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "veewom/cta-box",
"version": "1.0.0",
"title": "Veewom Call to Action Box",
"category": "design",
"icon": "megaphone",
"description": "A high-converting CTA box with customizable title and button.",
"supports": {
"html": false,
"color": {
"background": true,
"text": true
},
"spacing": {
"margin": true,
"padding": true
}
},
"attributes": {
"heading": {
"type": "string",
"default": "Ready to Learn WordPress?"
},
"buttonText": {
"type": "string",
"default": "Get Started Today"
},
"buttonUrl": {
"type": "string",
"default": "https://veewom.com"
}
},
"editorScript": "file:./build/index.js",
"editorStyle": "file:./build/index.css",
"style": "file:./build/style-index.css"
}
The edit() function is a React functional component rendered inside the Gutenberg canvas. It utilizes the useBlockProps hook and WordPress UI components (RichText, InspectorControls):
import { __ } from '@wordpress/i18n';
import { useBlockProps, RichText, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, TextControl } from '@wordpress/components';
export default function Edit( { attributes, setAttributes } ) {
const { heading, buttonText, buttonUrl } = attributes;
const blockProps = useBlockProps( { className: 'veewom-cta-container' } );
return (
<>
<InspectorControls>
<PanelBody title={ __( 'CTA Link Settings', 'veewom' ) }>
<TextControl
label={ __( 'Button Target URL', 'veewom' ) }
value={ buttonUrl }
onChange={ ( val ) => setAttributes( { buttonUrl: val } ) }
/>
</PanelBody>
</InspectorControls>
<div { ...blockProps }>
<RichText
tagName="h3"
value={ heading }
onChange={ ( val ) => setAttributes( { heading: val } ) }
placeholder={ __( 'Enter CTA Headline...', 'veewom' ) }
/>
<RichText
tagName="span"
className="veewom-btn-preview"
value={ buttonText }
onChange={ ( val ) => setAttributes( { buttonText: val } ) }
/>
</div>
</>
);
}
The save() function defines the static HTML written to the MySQL database (wp_posts.post_content):
import { useBlockProps, RichText } from '@wordpress/block-editor';
export default function save( { attributes } ) {
const { heading, buttonText, buttonUrl } = attributes;
const blockProps = useBlockProps.save( { className: 'veewom-cta-container' } );
return (
<div { ...blockProps }>
<RichText.Content tagName="h3" value={ heading } />
<a href={ buttonUrl } className="veewom-cta-btn">
{ buttonText }
</a>
</div>
);
}
In senior developer interviews: "What is the difference between a static block and a dynamic block?" Static blocks save compiled HTML into the database via save.js (fastest, zero server runtime). Dynamic blocks return null in save.js and define a PHP callback (via render.php or render_callback in register_block_type) that runs on the server for each request, essential for querying live content like "Latest 5 Comments".
Expand your CMS mastery by studying these tightly integrated WordPress development topics:
Understand block controls, inspector panels, and user block interactions.
Package your custom blocks into standalone, reusable plugins.
Use custom blocks inside Block Themes and FSE templates.
Parse block markup into JSON objects for Next.js frontend rendering.