GCBGutenberg
Control Blocks
Buy

Building blocks

Writing a block

Each block has a tiny PHP/JSON schema in the theme and one React component in your Next.js (or Astro, or any HTTP-SSR) frontend. The same component renders both the editor preview and the public site — WordPress hits one route on your frontend to get the HTML when an author edits, and your frontend renders the same component for visitors.

Two ways to render a block:

  1. PHP render.php — standard WP block. The plugin auto-wires render: file:./render.php if it exists.
  2. React component on your frontend — drop the render.php. The plugin asks your frontend to render via its /wordpress/render/[block] route.

A block can use either; the plugin picks based on whether render.php exists. See README.md for the overall architecture.

Where blocks live

Text
themes/{active-theme}/blocks/{block-name}/
├── block.json          # Standard WP block metadata
├── block.fields.json   # GCB controls config (optional)
├── render.php          # Server-side render (optional — see "Rendering with a React component")
└── style.css           # Frontend + editor styles (optional)

Block name = directory name. WP registers it as gcb/{block-name}.

What you write

block.json

Standard WP block metadata. Nothing GCB-specific in here:

JSON
{
  "$schema": "https://schemas.wp.org/trunk/block.json",
  "apiVersion": 3,
  "name": "gcb/team-grid",
  "title": "Team Grid",
  "category": "widgets",
  "icon": "groups",
  "textdomain": "gcb",
  "attributes": {},
  "supports": {}
}

Rules:

  • supports: {} unless the block wants WordPress's own design tools. The ones that work through get_block_wrapper_attributes() are safe on a render.php block whose root element prints it (the scaffold does): align, anchor, className, spacing, color, typography, dimensions, shadow. Both the canvas (its wrapper takes the rendered root's classes and style) and the page get them. Leave out layout (it lays out the block's direct children, which on the canvas are GCB's repeater wrappers), html, lock and anything __experimental. A block rendered by a React component gets the support's attributes as props but has to apply them itself — keep {} there unless it does.
  • attributes should be {} — they're auto-generated from block.fields.json.
  • render is auto-wired by the plugin if render.php exists; no need to set it.

block.fields.json

GCB-specific. Declares Inspector controls; the plugin auto-generates the WP attribute defs from these.

JSON
{
  "controls": [
    {
      "id": "panel_main",
      "type": "group",
      "label": "Main",
      "controlsGroup": "settings"
    },
    {
      "id": "ctrl_heading",
      "type": "text",
      "label": "Heading",
      "attributeKey": "heading",
      "controlsGroup": "settings",
      "parentPanelId": "panel_main"
    }
  ]
}

For controls: id is unique within the block; attributeKey is required for non-group types.

The schema file is at schemas/gcb.schema.json — point your editor at it via $schema in your block.fields.json for autocomplete (optional).

Words first. The editor shows the panel that holds a block's words (its text, textarea, richtext, wysiwyg, url/link controls) first and opens it, because words are what people edit most. Other panels keep the order you wrote. Put the words in their own panel. Settings that only matter in one mode get conditionalLogic, so a choice that makes another meaningless hides it.

IMPORTANT: picking the right control type

Get this wrong and the attribute ends up the wrong shape (e.g. array instead of string), the component reads undefined, and the block looks broken. Pick by the shape of the saved value, not by what looks nicest in the UI:

You want…ControlStored typeNotes
Free-text single linetextstring
Free-text multi-linetextareastring
Rich text (bold, links, lists)wysiwygstringHTML. Often better as InnerBlocks — see below.
On/off toggletogglebooleanA real switch. Not a checkbox.
One-of-N from a small fixed set (≤4, visual)toggle-groupstringSegmented control. Single-value. Use for left/right.
One-of-N from a larger setselectstringDropdown.
One-of-N visible all at onceradiostringStacked radio buttons.
Many-of-N (checkbox column)checkbox-grouparrayVertical list of checkboxes.
Many-of-N (button row)button-grouparrayHorizontal row of toggle buttons. SAME data shape as checkbox-group (multi-select / array). NOT single-value — use toggle-group for that.
Single boolean questioncheckboxbooleanWhen a toggle switch is the wrong affordance.
NumbernumbernumberFree-typed.
Number on a fixed scalerangenumberSlider with min/max/step.
ColourcolorstringHex / theme palette.
Single imageimageobject{ id, url, alt, width, height, ... }.
Gallery of imagesgalleryarray[{ id, url, alt, ... }, ...].
Other media (PDF, video, etc.)fileobject
Linked post / pagepost-objectobject
Linked URLurlobject
DatedatestringISO date. Opens a calendar in a popover/modal.
Date + timedatetimestringISO datetime. Opens calendar + hour/minute picker (DateTimePicker).
Heading (text + level)heading-levelobjectCompound: text input + level select. Stored as { text, level }. Default offers H1-H6 + P + DIV + SPAN; restrict via levels: ['h2', 'h3']. React: const T = h.level; return <T>{h.text}</T>;.
Icon pickericonobject
Code snippetcodestring

Pins on a picture: hotspots or pin-map. Both put numbered pins on an image; they differ in where a pin's content lives.

UseWhenThe pins are
hotspotsEach pin carries a few short fields (a title, a line of text) and nothing else.Rows inside the one field — { image, pins: [{ point, … }] }. Edited in the sidebar.
pin-mapEach pin opens a real card: its own block, with fields, an icon, rich content, its own canvas editing.The block's repeater children. The field holds only the picture; each child holds its point (or, with pointsKey, a list of locations — 06a, 06b). Adding a pin adds a card.
pointOne spot on an image the block already has (a focal point, a single marker).One { x, y }.

Rule of thumb: if you would want to edit a pin's content on the canvas, or give it more than three fields, it is a pin-map. Don't use both on one block.

Bias toward InnerBlocks for prose-y content. If the field is going to hold paragraphs of text — let alone paragraphs + lists + images — use a free InnerBlocks slot in the React component instead of a wysiwyg control. Authors get all of Gutenberg's tools, not a cramped Inspector textarea. See "Rendering with a React component" below for how blocks emit the <innerblocks> marker.

Common AI mistakes to avoid:

  • Don't reach for button-group for left/right or on/off. It's a multi-select (same array shape as checkbox-group, just rendered as a row of toggle buttons). Use toggle-group (single-value segmented) or toggle (boolean switch).
  • Don't use checkbox for "is this enabled" — toggle reads as a real switch and is the WP-native affordance for on/off.
  • If a control should store a non-default attributeType (e.g. a text field that should be number), set it explicitly. The auto-detection has sensible defaults but they're per-control-type, not per-use-case.
  • When in doubt, prefer fewer controls + an InnerBlocks slot in the component. WordPress is good at block authoring; the Inspector is best for short typed atoms.

IMPORTANT: discover the full control surface before using it

The table above tells you which control to pick. It does not list every field a control stores. Rich controls like image, gallery, url, icon, spacing, size, post-object, relationship, etc. store multi-field objects with toggleable features (focal point, size mode, custom width, isFixed, etc.).

If you build a component that reads only image.url and image.alt, you have silently dropped focal-point, cover/contain, custom width, fixed-background — every other feature the author can configure. The block ships looking broken.

Rule when using any control in block.fields.json or reading its value in a React component:

Before you write the code, Read the file src/controls/{type}.js in the plugin. The header JSDoc comment is the authoritative API contract — stored shape, every field, every feature toggle.

This is on purpose: hand-maintained docs go stale the moment a control changes. The control file is the source of truth. Reading it costs one tool call; getting it wrong costs a re-implementation.

When wiring a component:

  1. Read src/controls/{type}.js for the stored shape.
  2. Honour every documented field, not just the obvious ones. If the control stores a focal point, your <img> should set object-position. If it stores size, set object-fit. If it stores customWidth, use inline width. If isFixed, set background-attachment: fixed when used as a background.
  3. If a feature genuinely doesn't apply to this block's use case (e.g. the image is foreground-only so isFixed is meaningless), add a one- line comment explaining the omission. That way the next person doesn't wonder if it was forgotten.

Defaults reasonable when the field is absent (focal point defaults to 0.5/0.5; size defaults to cover; customWidth empty means no override).

render.php

Standard WP render callback. Receives $attributes, $content, $block in scope:

PHP
<?php
$heading = $attributes['heading'] ?? '';
$wrapper_attributes = get_block_wrapper_attributes(['class' => 'gcb-team-grid']);
?>
<div <?php echo $wrapper_attributes; ?>>
    <?php if ($heading) : ?>
        <h2><?php echo esc_html($heading); ?></h2>
    <?php endif; ?>
    <?php echo $content; ?>
</div>

Always get_block_wrapper_attributes() and echo it on the root element. Always escape dynamic values.

What you do not write

  • No edit.js / save.js — the plugin renders the Inspector UI from gcb.controls.
  • No hand-written attributes in block.json — they're derived.
  • No webpack config per block.

Built from GCB Lite 0.4.0 (ce232d4). Source: AGENTS.md.

Copyright © 2026 Runchain. WordPress is a trademark of the WordPress Foundation.