GCBGutenberg
Control Blocks
v1.3.3
Buy

Callout

A note, tip or warning box your client types into on the page. The smallest example. Every file shown in full.

A callout: a box that makes a short message stand out, as a note, a tip or a warning. Your client types the heading and the text on the page and picks the tone. It is the smallest example here: three plain files in your theme and a stylesheet. The tutorial builds it one file at a time.

Download example A zip of one block folder for your theme. Needs GCB 1.3.1 or later, and nothing else.

The whole block

Create blocks/callout/ in your theme. The folder name is the block's name, so this registers as gcb/callout.

block.json is WordPress's standard block metadata. There are no attributes in it and no render key: GCB makes the attributes from the fields and finds render.php by itself.

blocks/callout/block.json
{	"apiVersion": 3,	"name": "gcb/callout",	"title": "Callout",	"description": "A box that makes a short message stand out. Your client types the words on the page and picks its tone.",	"category": "design",	"icon": "megaphone",	"supports": { "html": false },	"style": "file:./style.css"}

block.fields.json lists three fields. The heading is required and limited to 60 characters, and the text to 240. Tone is a select: a dropdown of three choices that stores the chosen one's value as a string.

blocks/callout/block.fields.json
{	"controls": [		{ "id": "c_heading", "type": "text", "label": "Heading", "attributeKey": "heading", "default": "Good to know",			"validation": { "required": true, "maxLength": 60 } },		{ "id": "c_text", "type": "textarea", "label": "Text", "attributeKey": "text", "default": "Say the one thing your reader shouldn't miss.",			"validation": { "maxLength": 240 } },		{ "id": "c_tone", "type": "select", "label": "Tone", "attributeKey": "tone", "default": "note",			"options": [				{ "value": "note", "label": "Note" },				{ "value": "tip", "label": "Tip" },				{ "value": "warning", "label": "Warning" }			] }	]}

render.php is the template, for the editor and the page alike. It reads the values from $attributes. An element with data-gcb-field="<attributeKey>" and data-gcb-field-type="<type>" is edited where it sits on the page. A field with no marker appears in the block's sidebar.

The heading and the text have markers. Tone has none, so it is a setting in the sidebar. The template checks it against the three values it knows and falls back to note.

blocks/callout/render.php
<?php/** * Callout: a heading and a short message in a box, in one of three tones. * * The heading and the text are marked data-gcb-field, so they are typed where they sit on the page. * Tone has no marker, so it appears in the block's sidebar. * * @var array $attributes The block's field values. */ $tones = array( 'note', 'tip', 'warning' );$tone  = in_array( $attributes['tone'] ?? '', $tones, true ) ? $attributes['tone'] : 'note';?><aside <?php echo get_block_wrapper_attributes( array( 'class' => 'callout callout--' . $tone ) ); ?>>	<p class="callout__heading" data-gcb-field="heading" data-gcb-field-type="text"><?php echo esc_html( $attributes['heading'] ?? '' ); ?></p>	<p class="callout__text" data-gcb-field="text" data-gcb-field-type="textarea"><?php echo esc_html( $attributes['text'] ?? '' ); ?></p></aside>

style.css is a plain starting look, loaded by "style": "file:./style.css" in block.json. Replace it with your design.

blocks/callout/style.css
.callout { padding: 20px 24px; border-left: 4px solid #3b6fd4; border-radius: 6px; background: #eef3fc; color: #1d1b18; }.callout--tip { border-left-color: #2e8b57; background: #edf7f1; }.callout--warning { border-left-color: #c9831a; background: #fdf5e6; }.callout__heading { margin: 0 0 6px; font-weight: 700; }.callout__text { margin: 0; line-height: 1.6; }

That is all of it. There is no edit.js, no npm and no build step: save the files, reload the editor, and the block is in the inserter.

What your client does

  • Clicks the heading or the text and types.
  • Picks Note, Tip or Warning under Tone in the sidebar.

They can't save the page with no heading, or with a heading longer than 60 characters, and they can't change the colours.

Use it

  1. Unzip the download.
  2. Copy callout/ into your theme's blocks/ folder.
  3. Reload the block editor. Callout is in the inserter.

That's all of it. You don't register the block: there's no register_block_type() call and nothing to add to functions.php. GCB registers every folder in your theme's blocks/ folder by itself.

More examples: all examples, or download them together as the GCB Kit. To build one from nothing, see how to build a block.

Build anything in the block editor

Every licence includes all features and a year of updates and support.

Buy GCB from $8.25 a month See pricing