What is an attachment in WordPress?

WordPress Core

An attachment is any file uploaded to the WordPress Media Library. WordPress stores each attachment as a special post type (post_type = attachment) in the database, alongside its metadata: title, alt text, caption, description and file URL.

How WordPress stores attachments

When you upload a file, WordPress creates a database record in wp_posts with post_type set to “attachment”. The file URL, MIME type and other properties are stored in wp_postmeta. The physical file is saved to the server under /wp-content/uploads/ organised by year and month.

Each attachment has a unique numeric ID — the attachment ID. This ID is used throughout WordPress to reference the file in blocks, custom fields, theme options and the REST API. When you delete an attachment, its database record and physical file are both removed.

Attachment metadata

Every attachment can carry four metadata fields editable in the Media Library: title (the file’s name as displayed in admin), alt text (accessibility description for images), caption (visible text displayed below the image on the front end), and description (internal notes, rarely displayed). Missing or incomplete metadata affects both accessibility and Media Score in Mediapapa.

Frequently asked questions

What is the difference between an attachment and a media file?

They refer to the same thing. “Attachment” is the WordPress technical term — it refers to the post_type = attachment database entry. “Media file” is the common language equivalent. Every media file in WordPress is stored as an attachment.

Can an attachment exist without being attached to a post?

Yes. Files uploaded directly to the Media Library without being inserted into a post are called unattached media. WordPress tracks them but does not associate them with any content. They are not the same as unused media — an unattached file can still be referenced in custom fields or other contexts.

What happens to attachments when a post is deleted?

By default, attachments associated with a deleted post are not deleted. They remain in the Media Library as unattached files. You can delete them manually.