To keep your images out of Google Images, block Google’s image crawler, Googlebot-Image, in your site’s robots.txt file. You can also send a noindex X-Robots-Tag HTTP header with the image files. Google says the two methods “have the same effect”, so pick whichever is easier on your setup.
Both are covered below, along with what the noimageindex meta tag does and how to get images that are already in Google Images removed. The rules follow Google’s own guide to removing images.
Block a single image with robots.txt
The robots.txt file has to be at the root of the site that serves the images, for example https://example.com/robots.txt. If your images load from a CDN or another subdomain, that host needs its own robots.txt. To block one image, add:
User-agent: Googlebot-Image
Disallow: /images/dogs.jpgCode language: plaintext (plaintext)
The above rule blocks dogs.jpg from appearing in Google Images. Add one Disallow line per image to block several. To block a whole folder, end the path with a slash, for example Disallow: /images/private/.
Block a specific file format
To block all .gif images from appearing in image search, add:
User-agent: Googlebot-Image
Disallow: /*.gif$Code language: plaintext (plaintext)
Google supports two wildcards in robots.txt paths: * matches any sequence of characters, and $ marks the end of the URL. So this rule matches every URL that ends in .gif, in any folder. Paths are case-sensitive, so a file named PHOTO.GIF needs a second rule (Disallow: /*.GIF$), and because of the $, a URL with a query string such as /image.gif?v=2 is not matched.
Block all images
To keep every image on your site out of Google Images, add:
User-agent: Googlebot-Image
Disallow: /Code language: plaintext (plaintext)
This only affects Google Images. Google’s documentation adds: “If you would like to exclude the images from all Google searches (including Google Search and Google Images), specify the Googlebot user agent.”
Two things to know before you edit robots.txt. First, a crawler follows only the most specific User-agent group that matches it, so once you add a Googlebot-Image group, Googlebot-Image ignores your User-agent: * rules. Repeat any of those it should still follow. Second, Google generally caches robots.txt for up to 24 hours, so a change is not picked up instantly.
Block images with the X-Robots-Tag header
The alternative is a noindex X-Robots-Tag in the HTTP response of the image files. An image file cannot carry a meta tag, so the header is how you send noindex for an image. Google needs to fetch the image to see the header, so do not also block the same images in robots.txt. In Google’s words, “you must allow crawling the image URLs in order for Googlebot to be able to extract the noindex rule.”
On Apache, add this to the .htaccess file in your site’s root folder (or in the folder that holds the images) to send the header with every PNG, JPEG, GIF, WebP and AVIF file:
<IfModule mod_headers.c>
<FilesMatch "(?i)\.(png|jpe?g|gif|webp|avif)$">
Header set X-Robots-Tag "noindex"
</FilesMatch>
</IfModule>Code language: Apache (apache)
The (?i) makes the match case-insensitive, so .JPG files are covered too. On Nginx, add a location block to your site’s server configuration and reload Nginx:
location ~* \.(png|jpe?g|gif|webp|avif)$ {
add_header X-Robots-Tag "noindex";
}Code language: Nginx (nginx)
If your Nginx configuration already has a location block for images, for example one that sets cache headers, put the add_header line inside that block instead. Nginx uses only the first regular-expression location that matches, so a second block for the same files is ignored. Also, an add_header inside a location block stops that block from inheriting add_header lines from the server block, so copy any you still need.
Either way, check the result on a real image URL with curl -I https://example.com/wp-content/uploads/photo.jpg and look for the X-Robots-Tag: noindex line. If your images go through a CDN, check the URL the CDN serves.
What the noimageindex meta tag does
The noimageindex robots meta tag goes in the <head> of a page and tells Google not to index the images on that page:
<meta name="robots" content="noimageindex">Code language: HTML, XML (xml)
It works per page, not per image. Google warns that “if the same images also appear in other pages, they might get indexed through those pages.” To block a particular image wherever it appears, use the X-Robots-Tag header above. On WordPress, check your SEO plugin’s advanced robots settings for a per-post noimageindex option before editing theme files. To keep a whole post out of Google instead, see how to disable search engine indexing on a specific WordPress post.
Remove images that are already in Google Images
Blocking prevents future indexing. An image that is already in Google Images drops out the next time Google crawls it and sees the rule, which can take a while. If you need it gone quickly and the site is verified in Google Search Console, use the Removals tool: open Removals, select the Temporary Removals tab, click New request, choose Temporarily remove URL and enter the image URL.
Google says a request usually takes up to a day to process and is not guaranteed to be accepted, and that a successful one “lasts only about six months”. The removal is temporary, so keep the robots.txt rule or header in place. Without it, Google warns, “the images may resurface in Google’s search results once the removal request expires.”
For images of you or your content on sites you don’t own, the Removals tool won’t help. Google’s guide links to the right help pages for that case.
How to edit robots.txt on WordPress
WordPress has no robots.txt file on disk by default. It generates one when /robots.txt is requested. On WordPress 7.1 it looks like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/wp-sitemap.xmlCode language: plaintext (plaintext)
You have three ways to change it:
- Upload a real
robots.txtfile to the root of your domain (usually the folder that containswp-admin). The web server then serves that file, and WordPress’s generated version is no longer used, including anything an SEO plugin adds to it. - SEOPress PRO has a robots.txt editor under SEO > PRO > robots.txt. Turn on the robots.txt virtual file and write your rules in the text box. Other SEO plugins have similar editors. As SEOPress’s documentation notes, a physical robots.txt file takes priority over these virtual files.
- Add your rules with the
robots_txtfilter, shown below.
This snippet adds a Googlebot-Image group to the robots.txt that WordPress generates, and blocks everything in the media library from Google Images:
add_filter( 'robots_txt', function ( $output ) {
$output .= "\nUser-agent: Googlebot-Image\nDisallow: /wp-content/uploads/\n";
return $output;
} );Code language: PHP (php)
Open https://your-site.com/robots.txt afterwards to check the result. If an SEO plugin already manages your robots.txt, use its editor instead so the two don’t conflict.
Where to add this code
Add the snippet with a code snippets plugin instead of your theme’s functions.php, so it survives theme updates and you can switch it off without FTP. This step-by-step guide to safe code snippets uses the free Code Snippets plugin. On my own sites I use WPCodeBox, which keeps snippets in a cloud library so the same snippet can go on several sites. Not sure which plugin to choose? I compared Code Snippets, WPCode and WPCodeBox by feeding each one broken snippets. (Marius)
Disclosure: the WPCodeBox and SEOPress links are affiliate links. If you buy through them, I earn a commission at no extra cost to you.
How can i prevent a dedicated image folder from crawling/indexing by any search bot? Like Google search or image or bing search/image bot?
User-agent: Googlebot-ImageDisallow: /your-desired-folder/
This blocks all bots from crawling that specific folder and anything in it.