A media selector for choosing files from the WordPress media library with validation.
The File field opens the WordPress media library when clicked, allowing users to select or upload any type of file (PDFs, documents, archives, etc.). Unlike the Image field which is specifically for images, the File field is designed for all file types. You can configure which file types are allowed by specifying comma-separated extensions (e.g., “pdf,doc,docx”). The field validates files both when selected and when rendered, showing clear error messages if an invalid file type is attached. It stores the file’s ID, URL, and filename as an object.
Preview in Attributes Manager

Allowed File Types Configuration:
In the Attributes Manager, you can specify which file extensions are allowed by entering a comma-separated list like:
pdf– PDF files onlypdf,doc,docx– Microsoft Word documentszip,tar,gz– Archive files
Leave empty to allow all file types
File field. Preview in Gutenberg Editor


Technical Information:
| Property | Value |
|---|---|
| Gutenberg UI | Media upload button with file preview |
| Data Type | `object` |
| Contains | `id` (number), `url` (string), `filename` (string) |
| Default Value | `{"id": 0, "url": "", "filename": ""}` |
| Best For | Document uploads with file type validation |
| Common Uses | PDFs, documents, brochures, downloads, attachments |
| PHP Usage | See example below |
| Escaping | `esc_url()` for URL, `esc_html()` for filename |
| Configuration | Optional: Set allowed file types (comma-separated extensions) |
| Validation | Two-layer validation: on selection + on render |