Wp Block Development

Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports,

What Is This?

Overview

WP Block Development is a structured skill for building custom Gutenberg blocks in WordPress using the modern block API. It covers the full lifecycle of block creation, from defining metadata in block.json to registering blocks with PHP, handling attributes and serialization, and managing dynamic rendering through render.php or render_callback. The skill targets WordPress 6.9 and later, operating in a filesystem-based environment with Bash, Node.js, and optionally WP-CLI.

The skill addresses the complete technical surface of block authoring. This includes configuring supports for built-in editor features, writing deprecation handlers for backward compatibility, distinguishing between viewScript and viewScriptModule for frontend asset loading, and running build and test workflows through @wordpress/scripts and @wordpress/create-block. Each of these areas requires precise knowledge of WordPress internals and JavaScript tooling.

Modern block development has moved away from ad-hoc plugin patterns toward a standardized, metadata-driven approach. The block.json file is now the canonical source of truth for a block's identity, attributes, and capabilities. Understanding how this file drives both PHP registration and JavaScript editor behavior is essential for producing maintainable, upgrade-safe blocks.

Who Should Use This

  • WordPress plugin and theme developers building custom editor experiences for clients or products
  • Frontend engineers transitioning from classic WordPress development to the block-based paradigm
  • Full-stack developers who need to integrate server-side PHP rendering with React-based editor components
  • Development teams maintaining existing block libraries that require deprecation handling and migration paths
  • Agencies delivering headless or hybrid WordPress projects that depend on structured block output
  • Engineers responsible for performance optimization who need to control frontend script loading strategies

Why Use It?

Problems It Solves

  • Eliminates ambiguity in block registration by centralizing all metadata in a single block.json file, reducing mismatches between PHP and JavaScript definitions
  • Resolves confusion around dynamic versus static rendering by providing clear patterns for render.php and render_callback usage
  • Addresses frontend performance issues caused by loading editor scripts on the frontend by clarifying the distinction between viewScript and viewScriptModule
  • Prevents breaking changes in saved post content by providing structured deprecation and migration workflows
  • Removes build configuration overhead by leveraging @wordpress/scripts as a zero-configuration Webpack wrapper

Core Highlights

  • Full block.json schema coverage including name, title, category, attributes, supports, and editorScript
  • PHP registration via register_block_type_from_metadata() for automatic asset enqueueing
  • Attribute types including string, number, boolean, array, object, and null with source binding
  • Dynamic rendering patterns using both file-based render.php and inline render_callback
  • supports API for enabling spacing, color, typography, and other editor controls without custom code
  • Deprecation system for managing block schema changes across content migrations
  • viewScriptModule support for ES module loading on the frontend
  • Scaffold generation and test execution through @wordpress/create-block and @wordpress/scripts

How to Use It?

Basic Usage

Scaffold a new block using the official tooling:

npx @wordpress/create-block my-custom-block
cd my-custom-block
npm start

A minimal block.json file defines the block contract:

{
  "apiVersion": 3,
  "name": "myplugin/my-custom-block",
  "title": "My Custom Block",
  "category": "text",
  "attributes": {
    "message": { "type": "string", "default": "" }
  },
  "supports": { "html": false, "color": { "background": true } },
  "editorScript": "file:./index.js",
  "render": "file:./render.php"
}

Register the block in PHP:

function myplugin_register_blocks() {
    register_block_type_from_metadata( __DIR__ . '/blocks/my-custom-block' );
}
add_action( 'init', 'myplugin_register_blocks' );

Specific Scenarios

Dynamic rendering with render.php: When block output depends on server-side data, place a render.php file in the block directory. WordPress passes $attributes, $content, and $block as variables automatically.

Adding a deprecation: When changing an attribute structure, add an entry to the deprecated array in edit.js with the previous attributes schema and a migrate function that transforms old data to the new format.

Real-World Examples

A testimonials block reads post meta at render time using render.php, ensuring content stays current without re-saving posts. A pricing table block uses supports.spacing to expose padding controls in the editor sidebar without writing custom CSS panel code.

When to Use It?

Use Cases

  • Building reusable content blocks for a design system shared across multiple WordPress sites
  • Creating blocks that query and display dynamic post data without client-side JavaScript
  • Migrating legacy shortcodes or classic widgets to native Gutenberg blocks
  • Developing blocks that must pass WordPress.org plugin review requirements
  • Implementing full-site editing compatible blocks for block themes
  • Adding custom sidebar controls using the supports API for spacing, color, and typography
  • Maintaining a block library across multiple WordPress major versions using deprecations

Important Notes

Requirements

  • WordPress 6.9 or later with PHP 7.2.24 or higher
  • Node.js and npm installed for running @wordpress/scripts build tools
  • WP-CLI available for certain registration and scaffolding workflows

FAQ

Q: How does the Wp Block Development skill help with block.json metadata in WordPress?

The Wp Block Development skill assists you in creating and managing block.json metadata for custom Gutenberg blocks. Using Happycapy, you can streamline the process and ensure compatibility with WordPress standards.

Q: Can this skill be used to register blocks using register_block_type_from_metadata?

Yes, this Skills feature allows you to utilize register_block_type_from_metadata efficiently. It helps automate block registration, making your workflow with the AI agent more productive.

Q: What support does the Happycapy AI agent provide for handling block attributes and serialization?

Happycapy’s AI agent guides you through defining block attributes and managing their serialization in Skills. This ensures your Gutenberg blocks store and retrieve data correctly.

Q: Does the Wp Block Development skill cover block supports configuration?

This Skills module includes expertise in configuring block supports, such as alignment, color, and typography options, for your custom Gutenberg blocks.

Q: How do I use Happycapy Skills to troubleshoot issues with custom block development?

You can leverage Happycapy Skills to diagnose and resolve problems in your WordPress block development process. The AI agent can suggest fixes for common issues with block.json, attributes, or registration.