File

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

Screenshot 2025 10 30 at 12.25.18

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 only
  • pdf,doc,docx – Microsoft Word documents
  • zip,tar,gz – Archive files

Leave empty to allow all file types

File field. Preview in Gutenberg Editor

Fancoolo wp file field
Fancoolo wp file field added file

Technical Information:

PropertyValue
Gutenberg UIMedia upload button with file preview
Data Typeobject
Containsid (number), url (string), filename (string)
Default Value{"id": 0, "url": "", "filename": ""}
Best ForDocument uploads with file type validation
Common UsesPDFs, documents, brochures, downloads, attachments
PHP UsageSee example below
Escapingesc_url() for URL, esc_html() for filename
ConfigurationOptional: Set allowed file types (comma-separated extensions)
ValidationTwo-layer validation: on selection + on render