Many users aware WordPress offers post and page as default post types for creating content. You can create addition custom post types using plugin like Custom Post Type UI. However, WordPress also offers few other post types for attachment page, reusable blocks, etc. In this article we will explore more on attachment post type in WordPress and what you should do with that.
What is an Attachment Page?
You can upload media files in WordPress admin panel from the editor or from “Media > Library”. WordPress uses attachment as a post type to access 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
Since the post or page also has a permalink, let us explain the attachment page with an easy to understand 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:
Example | URL Type |
---|---|
https://img.webnots.com/how-to-delete-user-in-wordpress/ | Post URL |
https://img.webnots.com/WordPress-User-Section.png | Image Address |
https://img.webnots.com/how-to-delete-user-in-wordpress/WordPress-User-Section/ | Attachment Page URL |
Remember, we use post name as a permalink setup and use separate subdomain img.webnots.com to hose all static files uploaded on the site. If you use the default uploads folder, then the image URL will look something like below (organized by month and date). Post and attachment URLs will change based on your permalink setup.
Example | URL Type |
---|---|
https://www.yoursite.com/how-to-delete-user-in-wordpress/ | Post URL |
https://www.yoursite.com/wp-content/uploads/2021/02/WordPress-User-Section.png | Image Address |
https://www.yoursite.com/how-to-delete-user-in-wordpress/WordPress-User-Section/ | Attachment Page URL |
Attached and Unattached
Now that you know the difference between post, image and attachment URLs. However, not all the uploaded images and files need to be attached to a post or page. You can also have images not attached to any post types in WordPress.
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 be in unattached status. For example, your logo and favicon are unattached images since they are not uploaded in post editor. It is possible to filter all unattached images from the Media Library. You can click on the “Attach” link and assign the image to any of your existing post or page.
WordPress generates attachment page for both attached and unattached media files. However, they will have different URL structure as below:
Example | Attachment URL |
---|---|
https://www.yoursite.com/attached-post-url/image-name/ | Attached Image |
https://www.yoursite.com/image-name/ | Unattached Image |
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.
How Does Attachment Page Look?
You can copy the attachment page URL and open in the browser. It will look something like below:
As you can see the page contains all other sections like header, comments, footer and sidebar based on your theme’s page layout. However, it has a single image without no other text content.
Redirecting Attachment
Since all attachment pages have single media file, it will be a big problem from search engine optimization perspective. For example, if you have one thousand images on your site, all these images will have an attachment page URL. In this case, Google will index thousand attachment pages in search results. It will create two problems for you:
- Attachment pages are thin content pages that will affect the quality and ranking of your site in Google.
- Users landing on the attachment pages will be disappointed as they don’t have any content other than an image. This will create bad user experience for your the visitor.
In order to avoid these problems, 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 by enabling “Redirect attachment URLs to the attachment itself?” option.
Few Important Points
You can view all attachment details in “wp-posts” table of your WordPress site’s database. This is the same table WordPress uses to store all post, page and any other custom post type’s content.
WordPress uses “attachment.php” for rendering attachment pages. Also offers “attachment_template” to use in the template hierarchy.
The URL of attachment pages on your site depends on the permalink settings and attached/unattached status.
Since attachment page only contains the uploaded image, it is a good practice to redirect them. Yoast and other SEO plugins offer this option to redirect attachment page to image URL.
There are no default options in WordPress to disable attachment pages.
Leave a Reply
Your email is safe with us.