Media Attachment Pages. Who needs ’em, right?

image_pdfimage_print

Attachment Page sampleOne of the oddities of WordPress is that just about everything is a post. Posts are posts. Pages are posts. The menu is a type of post. You can create any number of Custom Post Type (I’ve made CPTs for people, recipes, rental items, sponsors, clients, &c). And one that can drive you a bit batty: Media is stored as a post type. This causes two problems. The first is that you might miss that when you add media to your content, there’s a dropdown box labeled Link To that may be set to Attachment Page. Normally you’d want to choose Media File because that’s how you’d pop the image up in a lightbox. Honestly, over the hundreds of projects I’ve done since 2008, I’ve never had a use for a Media Attachment Page.(1)Okay, yes, you can build a custom Media Attachment page template and doll it all up to look like the rest of your site, though I’ve yet to see or hear of one. But hey, you do you. I’d love to see how it turns out. If you’ve never seen one, go ahead and click on the image at right. For the first time ever, I’ve purposely chosen that setting. Maybe you’ll see it as useless as I do. Go ahead, I’ll be right here when you get back– and you’ll have to click your browser’s back button to continue reading this post. While you’re in there, click on the tiny image again so you can see it blow up in a Lightbox and actually read it.

Now that you’ve seen the Attachment Page with the giant headline that says, helpfully, Attachment Page,(2)Because that’s the title I gave it in the Media Library. You can change it to say whatever you like. Since it’s a post, it acts like one. Change the title, let people comment on it, &c I can move on to the real reason I bring this up: Google indexes those pages. It came up in a discussion on Facebook today – a colleague has added organization members to a site she’s building and found that a search turns up not only that person’s bio but also their photo as an attachment page. There are two ways to fix this.

Yoast It

Redirect AttachmentsThe simpler way, if you’re already using Yoast SEO plugin (and you should, it’s excellent), is to flip a switch that redirects to URLs heading to those attachments so they go to the page where you’ve embedded the media. So, for instance, if a search somehow turns up the image above, clicking on that result will bring you to this post rather than that kind of generic, mostly useless attachment page. Slick.

If you’re not seeing those settings, chances are you haven’t turned on Yoast’s Advanced Settings page.

Code It

If you’re not using Yoast, you’re trying to keep your plugins to a minimum, or you simply prefer the coder way of doing this, there’s a simple snippet of code you can use. Create a PHP file in your child theme folder, call it image.php, pop in this little bit of code, and save the file:

…but you’re better off using Yoast because it’s a handy plugin and and an easy way to follow good SEO practices.

Two Caveats

If you’re using the coding example and you change themes, make sure you create an image.php file in your new child theme. Conversely, if you’re using the Yoast method and decide to stop using that plugin, create that image.php file in your child theme or find another plugin that will handle the redirect for you.

Bonus tip!

While you’re checking things out in Yoast, you might as well head over to XML Sitemaps -> Post Types tab and make sure that you have Media (attachment) set to Not in sitemap. If you’re running Beaver Builder or something similar you’ll also want to exclude that post type from the sitemap as well. Then go to XML Sitemaps -> Taxonomies and do the same for things like Format (post_format) and, in the case of Beaver Builder, Categories (fl-builder-template-category). If you’ve built a fairly complex site there will likely be other content that you don’t necessarily want or need to have showing up in your search results.

Asides   [ + ]

1. Okay, yes, you can build a custom Media Attachment page template and doll it all up to look like the rest of your site, though I’ve yet to see or hear of one. But hey, you do you. I’d love to see how it turns out.
2. Because that’s the title I gave it in the Media Library. You can change it to say whatever you like. Since it’s a post, it acts like one. Change the title, let people comment on it, &c

stuff we dig

FYI: yes, the above are affiliate links, so we do make a small amount of money if you follow them over and buy what they're selling. Thank you for helping pay our hosting costs!

Dave Kuhar

Dave runs Transmit Studio, a media creation lab in San José. He's built more websites with WordPress than he can remember. He likes hearing himself talk and writing about himself in third person.

3 Comments

  1. Jude Love on October 17, 2017 at 10:29 pm

    Invaluable help Dave – thanks again

  2. David Law on May 18, 2020 at 4:16 am

    You wrote: “Okay, yes, you can build a custom Media Attachment page template and doll it all up to look like the rest of your site, though I’ve yet to see or hear of one. But hey, you do you. I’d love to see how it turns out.”

    So here you go an example output from an image attachment page: https://seo-gold.com/lighthouse-report-optimized-images-load-faster-and-consume-less-cellular-data/revolution-slider-is-not-performance-seo-optimized/

    I use WordPress attachment pages for SEO reasons and have built a template and a couple of widgets to support it all. Images can be an important part of SEO, a single Post can have 10 images which means there’s 10 opportunities to expand the content. I add content to the image attachment pages as otherwise all you have is at best one image and a caption which is thin content!

    You can see on the example above there’s text content, also added a second image and at the bottom there’s comments (looks like a WordPress Post) and a widget labeled “Related”, the Related links are to other image attachment pages from the main Post.

    Below that are two other widgets, first is labeled “Recent SEO Articles”, that’s a recent posts widget, below that is an unlabeled derivative of the recent posts widget, rather than loading posts it loads attachments instead, so it’s a Recent Attachments Widget, though it only loads image attachments from posts within the same categories as the main post (advanced SILO SEO feature).

    This sort of setup could work really well for a photography site. It is a lot of extra work though, each attachment needs content, time has to be taken to optimise image names, image titles, writing social media meta data etc…

    I also use all the image attachment pages for social media promotion, the site I linked to has less than 200 posts, but over 1,000 images, I use a Twitter schedule script I built to share the posts and image pages and it results in hundreds of thousands of extra Twitter impressions every month for free.

    BTW found your page on page 2 of the “wordpress attachment page template” Google SERP, I was looking for a better way to load an image at the top.

    • Dave Kuhar on May 18, 2020 at 4:53 pm

      Thanks, David, this is good stuff! To be honest, I hadn’t considered going nearly as far as you have with attachment pages. I can definitely see the SEO value. As you said, it’s a lot of extra work. I can’t think of a client of mine who’d put in the effort, but for those looking to goose their SEO I’m going to keep this in mind.

      I notice on your site (reading through https://seo-gold.com/seo-meta-tags/) that the images with media attachment pages repeat the content in the main story. Is there a potential penalty there for duplicate content?

      Pretty cool to be on page 2 with our little blog!

      pssst… check out the “Fast Website SEO Design” graphic on your homepage. When I click on it I get a white screen.

Leave a Comment