GCBGutenberg
Control Blocks
Buy

Field type

file

Non-image attachment picker (PDFs, documents, archives, etc.). Opens the WP media library and stores a small attachment object.

Type: file · Stored attribute type: object

Stored value

{ id: number, url: string, filename: string, title: string }

Supports

  • Media library picker constrained by MIME type
  • Replace and Remove actions on the selected file

Config options

OptionTypeDefaultDescription
allowedTypesstring[]["application", "text", "image", "video", "audio"]MIME top-level types to allow in the media library picker (e.g. ["application", "text"] for PDFs and docs).

Gotchas

  • Despite the broad default allowedTypes, this control is intended for non-image uploads. Use image for images and gallery for collections.
  • When the value is unset the object is still present with empty fields — always check value?.url rather than truthiness of value.

Example

JSON
{ "id": "ctrl_brochure",
  "type": "file",
  "label": "Brochure PDF",
  "attributeKey": "brochure",
  "allowedTypes": ["application"],
  "parentPanelId": "panel" }

Consume

JSX

JSX
export default function Download({ attributes }) {
  const f = attributes.brochure;
  if (!f?.url) return null;
  return <a href={f.url} download>{f.title || f.filename}</a>;
}

PHP

PHP
<?php
$f = $attributes['brochure'] ?? null;
if (!$f || empty($f['url'])) return;
?>
<a href="<?php echo esc_url($f['url']); ?>" download>
  <?php echo esc_html($f['title'] ?? $f['filename'] ?? ''); ?>
</a>

Every field also takes the keys common to all fields.

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

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