Image Attachment Pages Indexed and Ranking - What Do I Do?

blog cover image
17
2.2K followers
Updated

I recently ran in the problem that my image attachment pages were indexed and ranking both faster and higher than the actual article with keywords I tried to rank for.

There are a couple solution for this problem, such as with the help of a plugin named Attachment Pages Redirect or by changing the attachment page. It can even be solved by the robots.txt or .htaccess file, but things get pretty complicated beyond the plugin method.

What Are Attachment Pages?

Whenever you upload an image to your WordPress dashboard (or through publishing posts with SiteContent), WordPress will "generate" or create links for each image. Within WordPress every image has its own page that displays some information. This page is rather empty, but it contains the title and alt attributes as well as the filename and the possible description. This means that Google can index it and see it as rankable keywords.

Why WordPress even created these attachment pages is a good question on its own, because they do not have much functionality, other than to display the image nicely on a page with your whole theme design showing around it. There is perhaps a good reason to index these beautiful looking images with their meta content, but it would rather take the user away from the actual content you intended to get visitors towards.

Attachment Pages and SEO

For SEO ther is absolutely no purpose in that at all, because you wouldn't want anything else to rank than your content.

The worst of it all, is that this Attachment page does not include the meta tag for noIndex, so search engines will index these pages too.

I noticed some of the images appearing even within my Sitemap! Total nightmare, I don't want them to rank at all.

How To Fix This Problem?

There is a multitude of problems to solve. First of all we got the sitemap issue, to make sure that you don't want search engines to index the attachment page, next up is the actual attachment page and what you can do with that.

Sitemap:

The sitemap issue is solved quite easily. If you happen to have created your sitemap through All-In-One-SEO's feature named Sitemap, you can simply switch off the indexing for attachment and images.

For other plugins for sitemaps, please refer to your manual/help documents. In Yoast there is also an option for this.

Attachment Page

You cannot remove the actual attachment page (at least not yet), because it is part of WordPress itself. What we can do is either:

  1. make sure that search engines don't index these pages
  2. redirect the visitor of an attachment page to its parent (originating) post

1A. Prevent indexing using meta tag in attachment page

You can prevent the index by a number of options, but most of them are harder to implement, because they require FTP access, or some form of code editing, that not everybody is ready for. It also means you might be editing files that might get overwritten by the next Theme update.

First up, is adding the meta noindex tag to the attachment page, which makes it easier for search engines to read that they shouldn't be indexing this page. I am not sure whether that command actually also removes things that were indexed already from before from the search index.

You can do that by editing the attachment.php file or the single.php file and adding the meta tag to it:


1B. Prevent Indexing using Robots.txt

You can open your robots.txt file and add the following line to it:

Disallow: /?attachment_id

don't forget to save (and perhaps re-upload if you used FTP).

2. Redirect The Visitor

Another great method is redirecting the user away from the attachment page directly to its parent page or post. This means that you can redirect to the original post where that image belongs to. This is probably something you would want in most cases, so that you redirect the traffic to the place that is important to you.

You can do this in the following ways:

  1. Using setting in All-In-One-SEO or Yoast
  2. Redirecting from within image.php
  3. Using a plugin

1. Using setting in All-In-One-SEO or Yoast

Both All-In-One-SEO and Yoast have an option to do the whole redirection process for you.

All In One SEO

Go to All-In-One-SEO general settings page, then scroll down to the advanced settings section:

The option you want to check for is "Redirect Attachments to Post Parent".

Make sure you save and then it should work. You can test it out by going to Media library and clicking on an image, then click on view attachment page. If clicking on the attachment page (and the image is linked with a post), shows you a post, then it is working perfectly.

Yoast

In older versions of Yoast, you could redirect attachment url's to parent post url, but as it seems as of right now, you can even completely disable the attachments page system.

This came as an surprise to me, because an earlier research showed me the above.

By default within the newer Yoast (as of writing, version 7.4.2), all attachments are disabled. The actual file links to the actual image file on the server. No longer will you get pages linked to it.

You find it by going to Media:


You can still enable it by disabling the default option of disabling the attachment pages. Then a few new options are presented:


2. Redirecting from within image.php

This is an advanced method, but saves you having to use extra plugins for short bits of code like this one.

Depending on whether or not your theme has an image.php file, you might have to create the file if not (you might need to get your FTP skills updated to do this type of stuff).

Within the file, you have to add the following code:


Make sure you save and (re-)upload using FTP.

3. Using a plugin

There is a plugin that does all this for you. It redirects the visitor either to:

  • the parent post or page
  • to the main webpage

You can find the plugin named "attachment Pages Redirect" from within your Plugins directory within WordPress. You can go there by going to Plugins - Add Plugin - Search for the plugin name. Install the plugin and activate it. That is all there is to it, everything else goes by itself.

Note: If you do have all-in-one-seo or Yoast, use those plugins instead.

You can find more info about the plugin here:
https://wordpress.org/plugins/attachment-pages-redirect/

Luckily I have the All-In-One-SEO plugin installed and so I don't need anything else than to change the setting on my settings page. It worked extremely well, for now all the attachment pages immediatly link back to the post. When the image doesn't have a parent post, it will link to your main page.

If you ran into this problem yourself, then I hope you are helped with this solution. It really helped for me.


Got any questions? Post them below!

Login
Create Your Free Wealthy Affiliate Account Today!
icon
4-Steps to Success Class
icon
One Profit Ready Website
icon
Market Research & Analysis Tools
icon
Millionaire Mentorship
icon
Core “Business Start Up” Training

Recent Comments

9

What a lifesaver! I did the old site:domainname.com check in Google recently and found all my images had been indexed. My initial suspicions had been raised when I got Google Search Console to recrawl my site and it came back with many more URLs than I expected for the content on my site.

I have followed your very easy instructions (who knew the solution was just a tick box away) and will await the results following Google's next crawl of my site.

Thank you for sharing your expertise.

Thank you for this detailed explanation. I was not aware of attachment pages being a problem. This post should make it easy to correct issue. Thanks so much.

You are welcome

This was really helpful, thanks!

happy to help out any time!

Thank you Steven!

Wayne

Gosh...never heard of these attachment pages before. Appreciate your detailed explanation and solutions. Definitely will have to bookmark for reference.

Debbie

Thanks for sharing!!!

Tried and True

Elaine

See more comments

Login
Create Your Free Wealthy Affiliate Account Today!
icon
4-Steps to Success Class
icon
One Profit Ready Website
icon
Market Research & Analysis Tools
icon
Millionaire Mentorship
icon
Core “Business Start Up” Training