Search code examples
phphtmlgoogle-image-searchnoindex

Stop indexing certain images


So I have a robots.txt file which contains:

User-agent: Googlebot-Image
Disallow: /

At most, it stops the indexing of a lot of images. However, I also have affiliate images that when you search come up in results in Google (and assumably other search engines too).

I was wondering if it was possible (I've searched with no results) to add a rel="noindex" to images, or equivalent.

The affiliate images are served through a PHP loop, so I was looking for a one line fix if possible, as well as knowing that I wouldn't have to manually add the code each time :)


Solution

  • Since the images are being served via PHP you can easily tell Google not to index them by sending a HTTP header designed specifically for this purpose.

    Just put this line before your image output:

    header("X-robots-tag: noindex");