Field type
url
URL picker with a custom display label and an "open in new tab" toggle. Stores all three together as a single object.
Type: url · Stored attribute type: object
Stored value
{ url: string, text: string, opensInNewTab: boolean }
Supports
- URL, display text, and target=_blank toggle in one field
- Default values via
default: { url, text, opensInNewTab }
Config options
| Option | Type | Default | Description |
|---|---|---|---|
default | object | Initial value, e.g. { "url": "", "text": "Learn more", "opensInNewTab": false }. |
Gotchas
- When
opensInNewTabis true, always emit bothtarget="_blank"ANDrel="noopener noreferrer"to prevent reverse-tabnabbing.
Example
{ "id": "ctrl_cta",
"type": "url",
"label": "Primary CTA",
"attributeKey": "primary_cta",
"parentPanelId": "panel" }Consume
JSX
export default function CtaButton({ attributes }) {
const cta = attributes.primary_cta;
if (!cta?.url) return null;
return (
<a
href={cta.url}
target={cta.opensInNewTab ? '_blank' : undefined}
rel={cta.opensInNewTab ? 'noopener noreferrer' : undefined}
className="cta-btn"
>
{cta.text || 'Learn more'}
</a>
);
}PHP
<?php
$cta = $attributes['primary_cta'] ?? null;
if (!$cta || empty($cta['url'])) return;
$new_tab = !empty($cta['opensInNewTab']);
?>
<a
href="<?php echo esc_url($cta['url']); ?>"
<?php if ($new_tab): ?>target="_blank" rel="noopener noreferrer"<?php endif; ?>
class="cta-btn"
>
<?php echo esc_html($cta['text'] ?? 'Learn more'); ?>
</a>Every field also takes the keys common to all fields.