Attachment
Attachment objects represent non-image file attachments in WordPress (PDFs, documents, videos, audio files, etc.). Like Image, you don't access attachments directly as a root provider — they appear when iterating over attachments in a Loop block or chaining into attachment fields.
For image attachments, see Image.
Attachment inherits everything from Post — id, title, slug, link, dates, author, parent, meta, edit_link, raw post_* fields, etc. The fields below are attachment-only.
In the WP media UI, the post fields are renamed:
contentis the attachment Descriptionexcerptis the attachment Caption (raw)
All Fields
| Field | Arguments | Returns | Description |
|---|---|---|---|
src | — | string | File URL |
caption | — | string | Caption (filtered through wp_get_attachment_caption) |
file | — | string | Relative file path (to uploads folder) |
file_loc | — | string | Absolute file path on server (requires upload_files) |
extension | — | string | File extension |
size | — | int | null | File size in bytes |
pathinfo | — | array | pathinfo() array (dirname, basename, extension, filename) |
Common Patterns
Display file type badge
{{ item.extension|upper }}
Link to download
<a href="{{ item.link }}">{{ item.title }} ({{ item.extension|upper }})</a>
Show file size
{{ item.size|number_format }} bytes
File type icon class
file-{{ item.extension }}