Where Should WordPress Attachment Pages Redirect? The File, the Post, or Nowhere
Keeping attachment pages, sending them to the file, or sending them to the post they came from: who each option suits, the fallbacks it needs, and how to roll it out safely.
In this article 7 sections
Most advice about WordPress attachment pages stops at "get rid of them". That part is settled for most sites: a page that holds one image and a title is not something a searcher wants to land on. The question that actually needs thought is where each one should go instead, because the three options send visitors to very different places.
What you are deciding about
When you upload a file, WordPress creates a post of type attachment for it, and with it a public page: your theme's single-post layout with the image (or a link to the file) in the middle. Its address is something like /summer-menu/grilled-peaches/ when the file was uploaded to a post, or /grilled-peaches/ when it was not. /?attachment_id=123 reaches the same page on any permalink setting.
WordPress 6.4 changed what new sites do. A site installed with 6.4 or later has attachment pages switched off, and a request for one is redirected to the file. Every site installed earlier still serves them, and upgrading WordPress leaves that as it was. So the sites with the most attachment pages, older blogs with years of uploads, are exactly the ones still showing them.
Option 1: Keep them
There are a few sites where an attachment page earns its place:
- A photography site whose theme gives the attachment template real work to do: a large view, the caption, camera details, previous and next links through the gallery, comments.
- An archive or library where each scan or document has a written description in its attachment page and people search for individual items.
The test is whether the page has text a visitor could not get from the file alone. If yours do, keep them, and make sure each has a caption or description worth reading. If they are the bare default template, this is not your case.
Option 2: Redirect to the file
This is what WordPress does on new installs, and what you get by setting the wp_attachment_pages_enabled option to 0 on an older one.
It is the simplest choice and it removes every thin page in one move. The cost is what happens to a person who clicks through: they land on a bare JPEG or PDF in the browser, with no navigation, no site header and no way to the article the image came from. For a PDF someone wanted to download, that is fine. For a photo in a recipe post, it is a dead end.
The file is the right destination for:
- Downloads such as PDFs, spreadsheets and audio files, where the file is what the visitor came for.
- Uploads that never belonged to a post: logos, header images, files uploaded straight to the Media Library.
- Files whose post is not public: drafts, private posts, password-protected posts.
Option 3: Redirect to the post the file was uploaded to
Here the attachment page sends visitors, with a 301, to the post the file was first uploaded to. Someone who found the grilled peaches photo lands on the grilled peaches recipe.
For most blogs and content sites this is the best destination for images, for three reasons:
- The visitor gets context. The image is there, inside the article it illustrates, with the rest of your site around it.
- Links consolidate. If other sites linked to an attachment page, which happens with galleries and image embeds, those links now point at a real article instead of a thin page.
- Nothing is lost. The image file keeps its address, so the image itself, in your posts and in image search, is untouched.
It needs one fallback: when there is no published, public post to send a visitor to, the file is the only sensible destination. A redirect to a draft would show a 404; a redirect to a password-protected post would show a password form.
It also has one quirk worth knowing. WordPress records a file's parent once, when it is uploaded. If you uploaded a photo to one post and later reused it in five others, its attachment page will always go to the first. That is usually still a relevant page, but if one particular attachment page gets real traffic, give it its own redirect rule to the best destination.
What not to do
- Redirect them all to the home page. Search engines tend to treat a redirect to an unrelated page as a soft 404, and the visitor loses what they were looking for.
- Delete the media to delete the pages. The pages go, and so do the images in your posts.
- Noindex them and leave them be. It keeps them out of results, but visitors following old links still land on a thin page, and crawlers keep fetching every one of them.
A sensible default, and how to roll it out
For a typical blog or business site, the combination is: images and other files attached to a public post go to that post, and everything else goes to the file. Before switching anything on:
- Check what you have. Open an image in Media → Library and follow View attachment page. If a themed page opens, the site has them.
- Look for attachment URLs with traffic. In Search Console's Performance report, filter pages by
attachment_idand by the slugs of a few image files. Most sites find none worth keeping. Note any that get clicks. - Add specific redirects for those few, to whatever page serves that visitor best, such as a gallery or a product page.
- Switch on the general redirect. Then request a couple of attachment URLs with
curl -sIand confirm a301and the rightlocation.
In Hydrogen SEO, step 4 is one switch: General → Permalinks → Redirect Attachment Pages, added in 0.0.28 and off by default. It applies the default above, sending each attachment page to its post when that post is published, public and not password-protected, and to the file otherwise. Redirects you created yourself in the Redirection Manager are checked first, which is what makes step 3 work. On a site installed with WordPress 6.4 or later, where attachment pages already go to the file, switching it on sends them to their post instead. Details are in attachment page redirects.
Without a plugin, the same logic is a short template_redirect function in a child theme. If you write your own, keep the fallback to the file for posts that are not public, and use a 301 so search engines move the attachment page's signals to the post.
What to expect afterwards
Nothing dramatic, and that is the point. Over the following weeks, as Google recrawls the old attachment URLs, they move to Page with redirect in Search Console's Pages report and drop out of the index. The posts they redirect to keep ranking as before, now without a few hundred thin pages beside them, and anyone following an old image link arrives somewhere useful.