Field type
text & textarea
The simplest controls. Single-line input (text) or multi-line (textarea). Both store a single string.
Type: text, textarea (alias listed in the doc) · Stored attribute type: string
Stored value
string
Supports
- Plain string values, no formatting
- Validation rules (required, minLength, maxLength, pattern)
- Placeholder text and inline help
Config options
| Option | Type | Default | Description |
|---|---|---|---|
default | string | Initial value if the author hasn't edited the field. | |
placeholder | string | Greyed-out hint shown when the input is empty. | |
helpText | string | One-line description shown below the input. | |
validation.required | boolean | Block save until the field is filled in. | |
validation.minLength | number | Minimum character count. | |
validation.maxLength | number | Maximum character count. Shown as "X / Y" counter in the editor. | |
validation.pattern | string (regex) | Regex the value must match. Enforced client- and server-side. |
Example
{ "id": "ctrl_eyebrow",
"type": "text",
"label": "Eyebrow",
"attributeKey": "eyebrow",
"default": "",
"placeholder": "e.g. New in beta",
"validation": { "maxLength": 60 },
"parentPanelId": "panel" }Consume
JSX
export default function MyBlock({ attributes }) {
const { eyebrow = '' } = attributes;
return eyebrow ? <span className="eyebrow">{eyebrow}</span> : null;
}PHP
<?php
$eyebrow = $attributes['eyebrow'] ?? '';
if ($eyebrow): ?>
<span class="eyebrow"><?php echo esc_html($eyebrow); ?></span>
<?php endif; ?>Every field also takes the keys common to all fields.