Skip to main content

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:

  • content is the attachment Description
  • excerpt is the attachment Caption (raw)

All Fields

FieldArgumentsReturnsDescription
srcstringFile URL
captionstringCaption (filtered through wp_get_attachment_caption)
filestringRelative file path (to uploads folder)
file_locstringAbsolute file path on server (requires upload_files)
extensionstringFile extension
sizeint | nullFile size in bytes
pathinfoarraypathinfo() array (dirname, basename, extension, filename)

Common Patterns

Display file type badge

{{ item.extension|upper }}
<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 }}