GCBGutenberg
Control Blocks
Buy

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

OptionTypeDefaultDescription
defaultobjectInitial value, e.g. { "url": "", "text": "Learn more", "opensInNewTab": false }.

Gotchas

  • When opensInNewTab is true, always emit both target="_blank" AND rel="noopener noreferrer" to prevent reverse-tabnabbing.

Example

JSON
{ "id": "ctrl_cta",
  "type": "url",
  "label": "Primary CTA",
  "attributeKey": "primary_cta",
  "parentPanelId": "panel" }

Consume

JSX

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
<?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.

Built from GCB Lite 0.4.0 (ce232d4). Source: schemas/controls/url.md.

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