Shortcut tip: Quickly Noindex 1000s of WordPress Attachment Pages


(I am a magician!) #1

WordPress creates attachment page for each uploaded media file. It comes in two forms.

Whatever, it is very thin content and invites Google Panda penalty.

So, we should always prefer keeping this kind of pages with meta robots noindex tag.

or, for non-attached media file.

One of my clients recently faced this problem because of her previous SEO’s mistake. They had forgotten to set noindex for attachment path after switching from All in One SEO to Yoast SEO plugin.

As a result, index counts increased rapidly and affected Site performance in the SERPs. In Google Analytics, the traffic graph was going downhill. As a webmaster, I can understand the frustration, when we lose traffic suddenly.

The blog for which I was working - originally, including post and pages, had roughly 300 pages. But index count 2900+

Screenshot: 04/Feb/2018, 08:59PM IST Before implementing the workaround.

indexing anything on the web is so easy in comparison to removing it. Sometimes search engine takes enough time to re-crawl the pages.

Newbies often do mistake in frustration by doing some stupid thing using robots.txt

Disallow: /blah-blah-blah/

More than good, it does harm. Even if you add a Disallow rule that doesn’t affect already indexed links.

Right way: We should prefer using meta robots only.

<meta name="robots" content="noindex,follow" />

Yoast SEO offers a one-click feature to set noindex for all media files.

Again… here some webmasters were doing mistakes by redirecting attachment to post. :man_facepalming:

Now, what’s about non-attached media file, that you never used in the post?

Is it suppose to be redirected? Never. Ref: Warning message. (Yoast SEO Version 6.3.1).

So, what’s the right way to use Yoast plugin for keeping noindex the attachment path?

  1. Don’t set redirect.

  2. Set noindex for Media

Well, this is great for the older version of Yoast SEO.

What’s new in Yoast 7.0?

Please do note, in Yoast SEO 7.0, redirect of attachment works little differently. For non-attached images, it will redirect to the image, instead of showing a thin web page.
So, in new version even if you keep redirected, it’s completely okay for non-attached media. In case you prefer avoiding redirect, you must manually set noindex.

Both are good options in latest version Yoast.

Back to topic.

Let me tell you what additionally I did for doing noindex attachment pages faster.

Now, I had little confusion in my mind…

  • Should I really include attachment path in the XML sitemap or not?

Some folks say that Sitemap should contain only those paths which we want to index. Now, even more, the scary thing is Google can email you N numbers of pages contains noindex tag.

I skipped all these talks.

I contacted @shafi via Twitter, he introduced me a very interesting method for doing noindex fastly.

In short, this post says …

If you want to deindex your pages from Google, you’ve got the answer straight from the mouth of Google.

  • Change to meta robots noindex
  • Use the lastmod date to reflect the change
  • Update your XML sitemap

I just implemented this technique, and my attachment pages started to noindex in Google.

Here’s the result: Index counts from 2907 to 428. Thankfully, this worked for me.

Screenshot: 11:20 PM 3/26/2018

Let’s jump into behind the scene - Technical stuff.

How to create XML sitemap that will help in noindexing attachment pages?

You don’t need to write XML code. I have a shortcut approach. :stuck_out_tongue:

You just need to follow for a moment…

  1. Install and activate Yoast 6.3.1, enable sitemap for attachment path.

  2. Avoid redirect

  3. Go to Title & Post > Set noindex for Media

  4. Include Media in the Sitemap

  5. Go to source code of view-source:

  6. Copy the XML code to Notepad++ Application

    Hint: For better visibility, highlight XML code by going to Language menu & choose XML.

  7. Now, we need to tweak date/time of the last modified in this XML Sitemap. Press CTRL+H (Replace command).

  • In find field, type <lastmod>(.+)</lastmod>
  • Check Regular Expression
  • In replace field, it’s time to trick with latest Timestamp. :stuck_out_tongue:


So, finally press “Replace all” button.

Recap… this is what I did.

  1. Once ready, upload to root directory where you can easily access. I had named it workaround.xml

  2. Submit to Search console.

  3. Wait for a week. You will notice, Google will start dropping attachment pages from the SERPs quickly.


  • How to know if by mistake I am indexing Attachment pages?

Try searching on Google any post permalink, if you see more than one URL, chances are you might be indexing Attachment pages which is bad for SEO.

  • Why this method works?

Changes in lastmod at XML sitemap hints Googlebot for re-crawling the WordPress Attachment Pages. In presence of the meta robots noindex tag at Attachment pages, Google consider de-indexing it from the SERPs. It is a similar approach like we show last updated date for an old article instead of publishing date.

  • Hey, I am facing difficulty in writing Timestamp in the UTC format?

No worries, just update a post and copy its last modified Timestamp from the XML sitemap source code.

I hope this helps. Let me know what do you think about this?


Thanks & Regards,

Lost search ranking? A bug in Yoast may be to blame
Lost search ranking? A bug in Yoast may be to blame
(Wands Blog) #2

I have a quick question about not redirecting image to post/ page.

What will happen in this scenario - Visitor right clicks on an image and opens it in a different tab. They will see image alone and can right click and save (meaning steal my image). Am I right? With redirect option enabled, the blog post or blog page will open instead of image alone. Isn’t it?

Thank you!

(Next daily_dose topic request :slight_smile: : What is the best way to add affiliate links to blog posts and pages. Something that can be easily added and removed in future if necessary without editing each blog post. )

(Hitesh Rawat) #3

Want to do this on a site, is it safe to downgrade from 7.0 to 6.3?

Update: Did it. :slight_smile:

(I am a magician!) #4

Try this! :slight_smile:

Step 1. Go to any post/page where any image contains
Step 2. Right-click/Long tap on an image and choose ‘Save images as’ from the context menu. As you can see, we can still copy without opening in any tab.

For example-

Sorry, It doesn’t matter either redirect happens or not. One can copy anytime if they want.
Second, a visitor cannot find easily the attachment page, unless you hyperlink to the image.

(Shafi Khan) #5

Great guide Gulshan. You elaborated every minor aspect. And thanks for mentioning me :grin:

(I am a magician!) #6

Well deserved, mention. :slight_smile:
Thanks for help.

(Wands Blog) #8

Thanks for the pep talk :grin:

(Hitesh Rawat) #9

@gulshankumar started receiving these mails.

What should I do, what do you suggest??

(I am a magician!) #10

I take it as basic notification. It’s normal. Look at report, if it makes sense then okay, else just a notification. Nothing to panic.

(Hitesh Rawat) #11

Should I remove the sitemap from Google Webmaster tools now?

(I am a magician!) #12

If pages has been removed properly then, you should. Else you can keep for few weeks.

(Enjoy Your Life) #13

The problem only occurs when we include noindex follow pages in the sitemap. if we have noindex page then there is no need to include those pages to sitemap.

(sachin) #14

anybody can help me with teamviewer in removing these indexed attachments i did not understand this properly need help my site is losing rankings @gulshankumar

(sachin) #15

i followed this guide but my indexed page increased from 470 to 590 plz help @gulshankumar

(Enjoy Your Life) #16

Anyone used this plugin:

(I am a magician!) #17

If your attachment pages has been indexed by mistake, you can use above plugin to noindex.

(Enjoy Your Life) #18

Thanks, Going to install.

(I am a magician!) #19

You’re welcome!