WordPress attachment pages indexed in Google: why they exist and how to switch them off
WordPress gives every uploaded file a page of its own, and Google can list those thin pages. Since WordPress 6.4 one option, wp_attachment_pages_enabled, turns them into redirects to the file. A new site has them off. A site upgraded from an older version still has them on.
- By
- WP Ministry
- Published
- Tested on
- WordPress 7.1.3, PHP 8.3.35
In short
- Every file in the Media Library is stored as a post and has a page of its own, the attachment page, at its own address.
- WordPress 6.4 added the option wp_attachment_pages_enabled. It is 0 on a site installed since then and 1 on a site upgraded from an earlier version.
- With the option at 0, an attachment address answers with a 301 redirect to the file itself, not to the post the file was uploaded to.
- To see which you have, run wp option get wp_attachment_pages_enabled, or open an image in the Media Library and read whether the link says "View attachment page" or "View media file".
- No Settings screen holds the option. Change it with one WP-CLI command.
- Google drops a redirected address after it has crawled it again. Its documentation gives no fixed time for that.
Every file you upload to WordPress gets a page of its own, called an attachment page, with its own address. Unless you have written something on it, that page holds one image and a title, and Google can list it beside the pages you wrote. WordPress 6.4 added an option named wp_attachment_pages_enabled that turns each of those pages into a redirect to the file. A site installed on 6.4 or later has the pages off from the start. A site upgraded from an older version still has them on, and one command switches them off.
Advice written before that release tells you to install a plugin for this. On a current WordPress none is needed.
What an attachment page is
WordPress stores each uploaded file as a post of a kind of its own, attachment, and that kind is public. So an upload has two addresses: the address of the file, and the address of a page about the file. Where the page lives depends on where the file was uploaded and on the site's permalinks.
| The file | Its attachment page |
|---|---|
| Uploaded to a post or a page | The post's address with the file's slug after it: /harbor-walk/harbor-at-dawn/ |
| Uploaded straight to the Media Library | The file's slug at the top of the site: /harbor-at-dawn/ |
| Any file, on a site with plain permalinks | /?attachment_id=123 |
The ?attachment_id= form is answered on every site, whatever its permalinks.
These two commands list every attachment address a site has, then count them.
wp post list --post_type=attachment --fields=ID,post_title,url --format=csv
wp post list --post_type=attachment --format=countID,post_title,url
14,"Harbor at dawn",https://example.com/harbor-walk/harbor-at-dawn/
1While the pages are on, each of those addresses answers as an ordinary page. On a default theme it shows the file's title, the image at a reduced size, whatever was typed into the Description field in the Media Library, and a comment form. Its robots tag does not say noindex, and its canonical tag names the page itself. Nothing on it asks a search engine to leave it out.
WordPress's own sitemap does not list attachment pages. They are linked from wherever an image was inserted with its link pointing at the page: the block editor's image block offers "Link to attachment page", and its gallery block offers "Link images to attachment pages".
What WordPress 6.4 changed
Before 6.4, WordPress had no switch for this. The developer note for that release introduces the option wp_attachment_pages_enabled and says what it starts as.
| The site | The option | An attachment address answers |
|---|---|---|
| Installed on WordPress 6.4 or later | 0 | A redirect to the file |
| Upgraded from a version before 6.4 | 1 | The page, as it did before |
The upgrade sets 1 on purpose, so that a working site behaves as it did the day before. The result is that an older site keeps its attachment pages until someone switches them off.
What the address answers when the pages are off
It answers with a 301 redirect, sent by WordPress, to the file itself under wp-content/uploads. It does not go to the post the file was uploaded to, and it is not a 404. A visitor who follows an old link lands on the bare image. A crawler is told that the address has moved for good, to an image file.
Ask for one of your attachment addresses and read the answer:
curl -I https://example.com/harbor-walk/harbor-at-dawn/-I asks for the headers only. With the pages on, the first line says 200. With them off, these three lines are among the ones that come back:
HTTP/1.1 301 Moved Permanently
X-Redirect-By: WordPress
Location: https://example.com/wp-content/uploads/2026/10/harbor-at-dawn.pngX-Redirect-By: WordPress means WordPress itself sent the redirect. If that line names something else, a plugin or other code is doing the redirecting.
A few details that matter on some sites:
- A logged-in administrator gets the same redirect as a visitor.
- A file that is not an image is redirected the same way, to the file.
- On a site with plain permalinks,
/?attachment_id=123is sent to the file with?attachment_id=123still on the end. The file is served all the same. - A file uploaded to a post that is still a draft answers 404 at its attachment address, with the option on or off. The file's own address is public either way.
Check which setting your site has
There are three ways, and the last is the one that counts.
With WP-CLI. Run this from the site's main folder.
wp option get wp_attachment_pages_enabled1 means the pages are on and 0 means they are off. If WP-CLI answers with the error below, the option is not in the database. The likely reason is a WordPress older than 6.4, where attachment pages are always on: update WordPress first.
Error: Could not get 'wp_attachment_pages_enabled' option. Does it exist?In the dashboard. Go to Media, then Library, and click an image. In the window that opens, one of the links beneath the fields reads "View attachment page" when the pages are on and "View media file" when they are off. If the library is in list view, clicking opens the Edit Media screen instead, and the toolbar across the top says "View Attachment Page" or "View Media File".
By asking for an address. The curl -I command above shows what a crawler receives, whatever the option says. A plugin can redirect these addresses on a site whose option still reads 1.
Switch attachment pages off
Step 1: Set the option to 0
WP-CLI answers
Success: Updated 'wp_attachment_pages_enabled' option.The change applies from the next request. Nothing else has to be saved.bashwp option update wp_attachment_pages_enabled 0Step 2: Ask for an attachment address again
Run the
curl -Icommand from above against one of your own attachment addresses. The first line should now say 301, and theLocationline should name the file. If it still says 200, a page cache or a CDN may be holding a stored copy of the page: clear it and ask again.Step 3: Look at a post that shows images
Nothing about it changes. The files are where they were, at the same addresses, and the post shows them as before.
To bring the pages back, set the option to 1. Each page returns as it was, with its title and description.
wp option update wp_attachment_pages_enabled 1Without WP-CLI
No screen under Settings holds this option: not Media, not Reading, not Permalinks. The developer note names one other route, the address /wp-admin/options.php. That screen is headed "All Settings" and lists every option in the database as a raw field, under a warning from WordPress that things can be broken there. The note itself calls this route not usually recommended.
If it is the only way open to you, take a backup, change the field wp_attachment_pages_enabled from 1 to 0 and nothing else, and press "Save Changes". If your host gives you SSH or a terminal in its control panel, WP-CLI is the safer way.
What happens to the pages already in Google
Nothing changes in Google until it crawls each address again. When it does, it receives the 301. Google's documentation on redirects says that Googlebot follows a permanent redirect and that the redirect is used as a signal that the target should be the canonical address.
In Search Console's Page indexing report, an address like that is listed under "Page with redirect". The report's help describes that status as a non-canonical address that redirects to another, which will not be indexed. For attachment pages that status is the intended outcome. It is not an error to fix.
Google gives no fixed time for any of this. About recrawling in general, its documentation says: "Crawling can take anywhere from a few days to a few weeks." What you can do in the meantime is short:
- Leave the redirect in place. It is what does the work.
- Do not block the addresses in robots.txt. A crawler that is told not to fetch an address never learns that it now redirects, and Google's page on removing content says not to use robots.txt as a way to block a page. See where robots.txt is in WordPress and how to change it.
- For a few addresses that matter, the URL Inspection tool in Search Console can request a recrawl. Google says there is a quota, and that asking again for the same address does not make it go faster.
- For one result that has to go today, the Removals tool in Search Console hides an address from results for about six months. It hides the address and does not remove it. The redirect is what lasts.
The image files are not affected. Each stays at its address under wp-content/uploads, and the posts that show them still show them. Google's guidance on images says it learns what an image is about from the page the image is embedded in, including captions, titles and the text near it. That page is the post or page you put the image in.
When to keep attachment pages
Keep them when the page about a file is something you write and want people to visit. A photography or portfolio site is the usual case: every image has a title, a description and perhaps comments, and its attachment page is where those are shown. Switching the pages off takes that page away, and the Description typed in the Media Library is then shown nowhere unless your theme prints it somewhere else.
| Choice | The option | An attachment address answers | Fits |
|---|---|---|---|
| Off | 0 | A 301 to the file | A site that never writes these pages |
| On | 1 | A page, which a search engine may list | A site where each image's page has text of its own |
| On, kept out of search | 1, with the file below | A page that carries a noindex robots tag | Pages kept for visitors and not for search |
If you keep them, write them. A title that says what the image shows and a few sentences of description give the page something a title and a thumbnail alone do not.
Keep the pages for visitors and out of search
WordPress has no setting for this. It takes a noindex robots tag on attachment pages only, which a few lines on WordPress's wp_robots filter add. Create the folder wp-content/mu-plugins if the site does not have one, and save this in it as a file.
<?php
/**
* Asks search engines not to list attachment pages.
*/
add_filter(
'wp_robots',
function ( $robots ) {
return is_attachment() ? wp_robots_no_robots( $robots ) : $robots;
}
);WordPress loads a PHP file in that folder on every request, and the Plugins screen cannot switch it off: to undo this, delete the file. Each attachment page then carries noindex, follow in its robots tag, and no other page changes. Google has to crawl a page to read the tag, so do not block these addresses in robots.txt either.
What an SEO plugin's setting was for
While WordPress had no switch of its own, SEO plugins supplied one. Yoast SEO's documentation describes its "Media pages" setting this way: media pages are disabled by default, which redirects each attachment address to the image itself, and a toggle named "Enable media pages" brings them back.
So on a site that runs such a plugin, the addresses may already redirect while WordPress's own option still reads 1. Go by what the address answers.
Related problems
- Pages in Google that you never made and that are not attachment pages, such as titles in another language or products you do not sell, are a different problem: someone else added them. See spam pages in Google.
- The whole site is missing from Google. Work through why a WordPress site is not on Google.
- You want to know what else WordPress hands a search engine with no plugin installed. See WordPress SEO without a plugin and the sitemap at wp-sitemap.xml.
- Other old addresses need to go somewhere. See how to set up redirects in WordPress.
- The option reads 0 and attachment addresses still answer as pages. Something else on the site is deciding. A one-time fix from WP Ministry covers one issue on one site and starts with a free diagnosis, which gives you a written cause and a fixed quote.
Common questions
Is there a checkbox for attachment pages in Settings?
No. The option is not on any Settings screen. It is changed with WP-CLI, or on the All Settings screen at /wp-admin/options.php, which WordPress's own developer note does not recommend for ordinary use.
Does switching attachment pages off delete anything?
No. The files, the Media Library and everything typed into its fields stay as they are. Only what the attachment address answers changes, and setting the option back to 1 brings each page back.
Will my images disappear from Google Images?
Switching the pages off changes no image file and no post. Each file is served from the same address as before, and the posts that embed it are the pages Google's image guidance says it reads to understand an image. What Google chooses to show is its own decision, and nobody can promise it either way.
I switched them off and the pages are still in Google. What now?
Ask for one of the addresses with curl -I. If it answers 301 with the file in the Location line, the site's part is done and Google has not crawled that address again yet. If it answers 200, clear any page cache or CDN and check the option again.
Can an attachment address go to the post instead of the file?
Not with this option. It always sends the address to the file. Sending each one to the post it belongs to takes redirects of your own: see how to set up redirects in WordPress.
- ResourceWordPress SEO audit checklist: what to check, in order, and how to check each item
- Error fix"Alternate page with proper canonical tag" in Search Console: what it means on a WordPress site
- Error fix"Blocked by robots.txt" in Search Console: when it is fine, and how to find the rule on WordPress
- Error fix"Blocked due to other 4xx issue" in Search Console: what it means on WordPress and what to do
- Error fix"Crawled - currently not indexed" on a WordPress site: what to leave and what to check
- Cost guideHow much does SEO cost? What sellers' surveys report, and what moves the price on a WordPress site

