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
| Option | Type | Default | Description |
|---|---|---|---|
allowedTypes | string[] | ["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. Useimagefor images andgalleryfor collections. - When the value is unset the object is still present with empty fields — always check
value?.urlrather than truthiness ofvalue.
Example
{ "id": "ctrl_brochure",
"type": "file",
"label": "Brochure PDF",
"attributeKey": "brochure",
"allowedTypes": ["application"],
"parentPanelId": "panel" }Consume
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
$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.