Making Good Use of WordPress Attachment Pages
The attachment page is a page dedicated to a simple attachment, such as an image. Many wordpress themes don’t create a specific view for attachments, which means you website and users miss out on a potential information source, and potential SEO gain.
What Is an Attachment?
In WordPress an attachment is an uploaded item. This may be an image, a zip file, a movie or a PDF document. Attachments are stored in the posts table, the same place where regular posts and pages are stored.
In fact, attachments are posts but they have a different post type – attachment. This method of storage provides easy access and querying, which translates to easier development and faster processing.
What Is an Attachment Page?
An attachment page is a singular type page. Singular page is an umbrella term, which encompasses different types of single pages such as the single post page and single custom post type pages. Since an attachment is a post it too has a single page. This is called the attachment page.
Your single post page is dedicated to your article. It displays the title, content, metadata, comments and so on. In a similar vein, your attachment page should be dedicated to the attachment shown. If it is an image it should show the title, the image, description, perhaps even comments and other information about the image.
Does My Theme Have An Attachment Page?
Do your wordpress themes have an attachment page? The answer to this question is yes and no. First of all, let’s take a look at how you can get to an attachment page.
In any old post, add an image and make sure to select “Attachment Page” in the link to dropdown. Update or publish your post and visit it in the front end. By clicking the image in the post you’ll be taken to an attachment page. It may not look good (depending on your theme) but it is an attachment page.
To understand why this is so, let’s learn a bit about template files. WordPress uses the template hierarchy to determine which file is used when a specific page is visited. Your front page probably uses index.php if it shows a list of posts; pages use page.php; single posts use post.php and so on.
It is called a hierarchy because there is a set hierarchical order in which the correct file is chosen. For example, let’s say you visit the tag archive for your “music” tag. WordPress looks for a tag-music.php file. If it doesn’t exist it looks for tag.php. If that doesn’t exist it uses archive.php. Eventually it falls back to index.php which is a required file so it always exists.
What this boils down to is that index.php is used whenever files further up in the template aren’t defined. Theme authors are used to single pages, archives, 404 pages and such but many forget about our friend the archive page. They forget to implement it and thus index.php is used.
if this is unintentional and the index.php file is not built to handle images, well, you may get some weird-looking attachment pages. If the theme author has implemented attachment.php or has built index.php that is mindful of attachments, your attachment page will look fine.
How Do I Create An Attachment Page?
If your theme doesn’t already have an attachment.php file you’ll need to create it.
If it is a theme created just for you, go ahead and add the file now. If however, you are using a third party theme you downloaded or installed from the repository, you should create a child theme. Child themes are used to extend existing themes without editing the original files. Once you’ve added a child theme (it’s super simple), create an attachment.php file in it.
Find the single.php file in your theme, copy the whole content and paste into the attachment page file you just created. In 70% of the wordpress themes out there this should be enough.
In a large portion of the remainder, you may want to delete some single post specific things. In some other cases, due to the way your single post page works, this may still not work as expected. If this so, try using the content of page.php instead.
Conclusion
Attachment pages are great because they give you an opportunity to offer something valuable to your readers: More information about your images, your thoughts on them, perhaps download links or even information about the camera and techniques used to capture it.
Rich information such as this ranks highly in Google if used consistently and correctly, which means it is far more than just eye-candy.
If you don’t have an attachment page yet, I recommend following this guide and creating one now. You can also download the wordpress themes on our website, most of they have a good deal with attachment page.