Attachment is a post type in WordPress that is used for any files uploaded and assigned to a post or page. For example, you can upload an image using an image block in Gutenberg block editor. WordPress will attach the uploaded image to that particular post and assign a unique URL to access the image.
Attachment URL Example:
Let us take an example that we upload an image named “WordPress-User-Section” to a post “how-to-delete-user-in-wordpress/”. In this case, below are the URLs you will get:
|https://wp-tips.com/how-to-delete-user-in-wordpress/WordPress-User-Section/||Attachment Page URL|
Attached and Unattached
You can view an image is attached or unattached from “Media > Library” section of your admin panel. Make the view to list view and check under “Uploaded to” column. If the image is already attached, you will see the post URL and “Detach” option.
If you have directly uploaded images through “Media > Library” section, then they will in unattached status. For example, your logo and favicon are unattached images since they are uploaded in post editor.
Where Can I See Attachment?
When you upload an image or media file through post editor, you will only see the “File URL”. This file URL is the image address and not the attachment URL. In order to view the attachment URL, go to “Media > Library” section and change the view to grid view.
Click on any image and then hover over the link at bottom that says “View attachment page”. This is the attachment page URL of the image you have uploaded.
Few Important Points to Note:
Since attachment page only contains the uploaded image, users landing on that page will get disappointed expecting some content. In order to avoid this, you can redirect all attachment page URLs to the uploaded image URL using Yoast SEO plugin. You can do this under “SEO > Search Appearance > Media” section of Yoast SEO plugin and enabling “Redirect attachment URLs to the attachment itself?”
You can view all attachment details in “wp-posts” table of your WordPress site’s database.
WordPress uses “attachment.php” for rendering attachment pages and offers “attachment_template” to use in the template hierarchy.
Article last updated on November 6, 2020