file
Non-image attachment picker (PDFs, documents, archives, etc.). Opens the WP media library and stores a small attachment 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
allowedTypesstring[]default:"[\"application\", \"text\", \"image\", \"video\", \"audio\"]"- MIME top-level types to allow in the media library picker (e.g. `["application", "text"]` for PDFs and docs).
Example
json
{ "id": "ctrl_brochure",
"type": "file",
"label": "Brochure PDF",
"attributeKey": "brochure",
"allowedTypes": ["application"],
"parentPanelId": "panel" }
Gotchas
Heads up
Despite the broad default `allowedTypes`, this control is intended for non-image uploads. Use `image` for images and `gallery` for collections.
Heads up
When the value is unset the object is still present with empty fields — always check `value?.url` rather than truthiness of `value`.
Notes
Consume
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>;
}