How to stop Google from indexing your WordPress image attachment pages

Have you ever actually checked how your website appears in SERPs? You might want to, especially if you are running WordPress. The reason is that when you upload an image and insert the normal way it creates a separate WordPress attachment page. And if you aren’t careful Google might actually start indexing these pages. You can see below in this picture that is what happened to me.

Attachment pages showing in SERPs
Attachment pages showing in SERPs

You can see above that “raventools” and “google-authorship” are actually the names of two image attachment pages. Example, below is what the raventools link goes to.

raven tools
WordPress attachment page

You can see that page is simply the attachment page that is created due to the image upload. Why is this a bad thing? It’s bad because in SERPs you have things showing up that are named wrong. Also, visitors are now hitting pages that are completely blank which may in turn lead to a higher bounce rate.

There are a couple of different ways to prevent Google from indexing your WordPress attachment pages.

Option 1 (preferred method)

The easiest way to fix this is to redirect the WordPress attachment pages to the original image itself. In this example I will show you how to do this using the Yoast SEO plugin. (there is also a similar setting in the All in One SEO plugin)

Note: Versions earlier than Yoast SEO 7.0 offered the option to redirect to a post or page. This method was removed from the plugin as it wasn’t reliable. I’m using the new option below (on all of my sites) to redirect to the image instead. It works well.

Step 1

In your WordPress dashboard, click into “SEO → Search Appearance.”

Yoast SEO search appearance
Yoast SEO search appearance

Step 2

Click on the “Media” tab. Then make sure the option to redirect attachment URLs is set to “Yes.”

Yoast SEO media & attachment URLs
Yoast SEO media & attachment URLs

Step 3

Click “Save Changes.”

Remember it may take some time for Google to pick up the changes. I recommend waiting a week or two before checking SERPs again.

Option 2

Another way to prevent this from happening is to click into the image attachment page and mark it as no-index within the Yoast plugin.


Option 3

A third way to prevent this as Olaf mentioned below in the comments is that you could block all of your attachment pages from indexing within your robots.txt file. I prefer option 1 as it is quick and easy.


Now your SERP listings should look cleaner and your visitors won’t be hitting blank pages. As always feel free to leave your comments below!

author bio
Brian Jackson

I craft actionable content and develop performance-driven WordPress plugins. Connect on X, subscribe to my newsletter (once a month), or buy me coffee.

43 thoughts on “How to stop Google from indexing your WordPress image attachment pages”

  1. Hi Brian,
    Please explain option 2 a bit more, how does it work? The attachment URL exists for every image and is not related to the fact that an image is linked to a post or not. Many themes require this option to build galleries and sliders. How about option 3 to use the robots.txt file and block the attachment URL for indexing? Anyway I use option 1 since year because it’s fix for something that Google is doing wrong.

    • Oops, ya that was my bad. You are correct, whether is it uploaded within the post or directly from the media library an attachment page is created regardless. I have updated the post above with 2 additional options (mentioned you). Obviously option 1 is the quickest and easiest way to fix this problem. Thanks for your comment and fixing my mistake!

      • Right this noindex option for media posts is an option I use too. You should use both WordPress SEO settings to get the job done. And for those using a different SEO tool this robots.txt entry should help:

        Disallow: /?attachment_id

        It’s not the best way to stop bots indexing them…

  2. Hey Brian thanks for this but I’m struggling to find a similar setting for Option 1 in All in one SEO? apart from no indexing media which is not what we want? Any pointers? cheers

  3. Why do you say visitors will be hitting blank pages? What about photography sites? There I guess you’d want the attachment pages to be found..

    • The attachment pages are different than your images indexing in Google image search. You never want anyone hitting an image attachment page.

          • But there’s still nothing wrong with people finding your images on the attachment page! If they’re nicely styled this is a good way of presenting them to online searches.

          • True :) I guess I have never seen a nice one. Most don’t have any styles on them because themes don’t style attachment pages. But depending on how the theme is setup I could definitely see it possibly working, especially if you are running a photography site.

          • Brian, I most def have to agree with Avalonica here! for example, my client has very big blog where each attachment page (for images) have bunch of tags that are related to that perticular image (not tags for parent post) so each of that tags (very scientific) will be very good SEO boost actually ,,it’s great to have that pages man :)

          • I am happy to be proven wrong :) but nobody has shown me a good example of a tag page in SERPs before. You mind sharing a URL? From my experience tags don’t help your SEO at all.

            Unless your speaking of it from a usability standpoint? Are you hoping someone will land on it and click a tag?

  4. Did you just recently implement options 1 and 2? Because it might take a bit for them to drop out of SERPs. You shouldn’t have to do all of the options above for it to work. Although nice to have options :)

  5. Did you then keep the setting in option 1 as well? Because when I do that I am getting a warning from yoast just above the media section in post types: “As you are redirecting attachment URLs to parent post URLs, these settings will currently only have an effect on unattached media items!”

  6. This is very helpful as I have way too many images on my website. People usually just go to the individual image post and bounce off from there. Hope your first option will help reduce bounce rates. Thank you!

  7. Congratulation for this post, Brian; what is for you best option that avoid permalink images indexed in serp but allow index for google images?

    • Using the Yoast SEO “redirect attachment URL” option seems to be the best to avoid image permalink from being indexed and still allowing for images to be indexed. That is how I have my sites setup.

  8. Hi, Does this have a negative impact on SEO when turning off for sites who have a history of their pages indexed in search.

  9. Thank you, woorkup. But I still have a question. Up until now, Google has been indexing my image attachment pages in search results. So after I try option 1, will Google remove my image attachment pages from search results?

    • Hey Jio,
      Yes, once Google crawls these URLs it will then realize they are redirecting to the post that the image is on or the image itself (depending on how you have it setup). So the attachment pages will slowly fall out of SERPs. This is what you want, as you don’t want visitors landing on these pages.

  10. It would be better if you do not want indexed attachment pages not to use a theme that has attachment pages. But redirecting the attachment page to the post is also a good solution. That’s my opinion.

  11. Thanks, You saved my day. How long search engine will take to remove them from index? I have redirected attachment urls to parent urls.

  12. Had the same Problem witch attachment pages of my first Wordpress Page/Blog showing up in Google. I activated the redirect function in Yoast now, so you saved me. BIG THX!
    But does Google de-index the attachment-pages already indexed so far?


Leave a Comment