Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared Managed Cloud India
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Best lists Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

SEO & AI search · Guide

How to Disable Attachment Pages in WordPress

Short answer

To disable attachment pages in WordPress, set the core option wp_attachment_pages_enabled to 0, or turn off media pages in Yoast SEO, or switch on Redirect Attachments in Rank Math. Any of these sends attachment URLs to the media file or the parent post with a 301 redirect, so the thin pages stop showing in search.

Key takeaways

  • WordPress creates a thin front-end page for every file you upload, and those pages add nothing for visitors or search engines.
  • New sites installed with WordPress 6.4 or later already have attachment pages disabled; upgraded sites do not.
  • Setting wp_attachment_pages_enabled to 0 redirects attachment URLs to the media file itself.
  • Yoast SEO redirects attachment URLs to the file when you switch off Enable media pages.
  • Rank Math redirects attachment URLs to the parent post, and orphan media need a separate target URL.

What is an attachment page?

An attachment page is a front-end page WordPress creates for every file you upload to the media library.

Every image, PDF or video you upload becomes a post of type “attachment” in the database, and each one gets its own URL. An image called sunset.jpg attached to a post called my-trip might live at example.com/my-trip/sunset/.

Open that URL and you see a bare page with the image and almost nothing else. There is no article text, no navigation context and no reason for a visitor to land there. That is the page you want to get rid of.

The file itself still exists at its normal address under /wp-content/uploads/. Disabling the attachment page never deletes the file or breaks the image where it is used.

Why should you disable attachment pages?

Attachment pages are thin pages with almost no content, and thin pages can drag down how search engines see your site.

The Disable Media Pages plugin page puts it plainly: attachment pages hold only an image, so they offer little value and can hurt your SEO. Google has nothing useful to index on them, and visitors who land there bounce straight back.

They cause a second problem with slugs. The same plugin page gives an example: upload an image named contact.jpeg and WordPress creates an attachment page at example.com/contact, which can block you from using that slug for a real page later.

They also waste crawl budget. Search engines spend time crawling hundreds of near-empty pages instead of your real content. Removing them keeps the crawl focused on pages that matter.

Are attachment pages already off on your site?

On sites installed with WordPress 6.4 or later, yes. On older sites that were upgraded, no, they are still on.

WordPress 6.4 added a database option called wp_attachment_pages_enabled that controls this behaviour. The Make WordPress Core dev note says new installations have attachment pages fully disabled, which helps SEO by keeping those thin pages out of search results.

Upgraded sites keep the old behaviour so that existing links do not break without warning. The dev note says there is no settings screen for the option, following WordPress's habit of not adding a toggle for every choice.

To check your site, open an attachment URL in a private browser window. If it shows the image on a bare page, attachment pages are still on. If it jumps straight to the image file, they are already off.

How do you disable them with the WordPress core option?

Set the wp_attachment_pages_enabled option to 0, using WP-CLI or the options page, and WordPress will redirect attachment URLs to the media file.

With WP-CLI installed, run wp option update wp_attachment_pages_enabled 0 from your site's folder. Then confirm the value with wp option get wp_attachment_pages_enabled, which should print 0.

Without shell access, open /wp-admin/options.php while logged in as an administrator, find the wp_attachment_pages_enabled row, change its value to 0 and save. Be careful on that page: it lists every option on your site, and a wrong change there can break things.

When the option is off, WordPress redirects each attachment URL to the file itself with a permanent redirect. The media library label also changes from “View attachment page” to “View Media File”, which tells you the setting took effect.

How do you disable them with Yoast SEO?

Turn off the “Enable media pages” switch in Yoast SEO, and every attachment URL will redirect to the media file itself.

  1. Go to Yoast SEO, then Settings in your WordPress dashboard.
  2. Open the Advanced section.
  3. Click Media pages.
  4. Slide the Enable media pages switch off.
  5. Save your changes.

Yoast's help page on attachment URLs explains that disabling media pages makes all attachment URLs redirect to the media itself. That is the current behaviour, and it is the default on a fresh Yoast install.

Older versions of Yoast did it differently. Before Yoast SEO 7.0, the plugin redirected attachment URLs to the parent post instead. Yoast's help page says that option was removed because it caused problems when one image appeared in several places on a site.

For the rest of the plugin's setup, our Yoast setup guide walks through each screen.

Our what Yoast does guide explains the plugin's main features.

How do you disable them with Rank Math?

Switch on Redirect Attachments in Rank Math, and attachment URLs will redirect to the parent post instead of opening a thin page.

Rank Math's guide on redirecting attachments puts the setting at Rank Math SEO, then General Settings, then Links. The Redirect Attachments option only appears in Advanced Mode, so switch modes first if you cannot see it.

Rank Math redirects an attachment to the post or page it was uploaded on. That only works for media uploaded inside a post or page. Files uploaded straight to the media library have no parent post, so they are orphans.

For orphans, Rank Math offers a second setting called Redirect Orphan Attachments. It takes a URL of your choice, and the default is your homepage. Rank Math's guide notes that leaving it blank means orphan attachment pages stay live, so fill it in.

If you would rather send attachments to the file itself, Rank Math offers a filter called rank_math/frontend/attachment/redirect_url that changes the target. Our Rank Math setup guide covers the plugin's first-run steps.

How do you disable them with code?

Add a small snippet that checks each page request and redirects attachment pages to the parent post or the file, using the template_redirect hook.

WordPress provides a check called is_attachment(), which tells you whether the current request is for an attachment page. The developer reference describes it as a test for an existing attachment page query.

A snippet hooked to template_redirect can use that check, then send a 301 redirect to the parent post with wp_safe_redirect().

It can also send the visitor to the file itself with wp_get_attachment_url(). Add it to a child theme's functions.php or through a code snippets plugin, never to the parent theme, or an update will wipe it out.

Use the core option or an SEO plugin instead if you can. Code works, but it is one more thing to maintain, and a mistake in functions.php can take the whole site down.

How do you check that it worked?

Open an attachment URL in a private window and confirm it lands on the file or the parent post, then check Search Console for the old URLs.

Pick an image from your media library, copy its attachment page address, and paste it into a private browser window. You should end up on the image file or the parent post, not on a bare page.

Check the redirect type too. A browser tool or a redirect checker will show the status code, and it should be 301, not 302. A 301 tells search engines the move is permanent.

Then open Google Search Console and watch the Pages report. The old attachment URLs should drop out of the index over the following weeks. If they linger, check that nothing else on the site still links to them.

What mistakes should you avoid?

The biggest mistake is turning the setting on and assuming the old pages vanish from search at once; they fade over weeks, not hours.

  • Do not use a plugin that returns a 404 for attachment pages unless you want the URLs gone, not redirected.
  • Do not leave orphan attachments unhandled in Rank Math by leaving the orphan field blank.
  • Do not edit the parent theme's functions.php for the code method; use a child theme or a snippets plugin.
  • Do not forget that old post content may still link images to attachment pages; those links need updating by hand.
  • Do not block attachment URLs in robots.txt instead of redirecting them, since a blocked URL can still show in search results.
MethodWhere the URL goesBest forWatch out for
Core optionThe media fileNew sites and clean setupsNo settings screen; use WP-CLI or options.php
Yoast SEOThe media fileSites already running YoastCheck the Media pages switch is off
Rank MathThe parent postSites already running Rank MathOrphans need a separate target URL
Code snippetYour choiceDevelopers who want full controlA mistake can break the site

Pick one method and use it on its own. Two redirect methods running together can fight over the same URL.

Frequently asked questions

Is it safe to disable attachment pages?

Yes, for most sites. Attachment pages hold almost no text, so they add nothing for visitors and can look like thin content to search engines. The exception is a photography site that wants each image to have its own page, but even then the file page is usually the better address.

Will disabling attachment pages delete my images?

No. Disabling the page only changes what happens when someone opens the attachment URL. The file stays in your media library at its normal address, and every post that uses the image keeps working.

Why are attachment pages still on if WordPress 6.4 disabled them?

WordPress 6.4 changed the default for new installs only, so that existing sites would not suddenly lose URLs people may link to. Older sites keep attachment pages on until you switch the option off yourself.

How long before the old attachment URLs leave Google?

They should fade from the index over the following weeks, since Google has to re-crawl each URL to see the redirect. You can speed this up by removing the old URLs from your sitemap and asking Google to re-crawl them in Search Console.

Why do some of my attachment pages still load after I set up a redirect?

Check the Redirect Orphan Attachments setting in Rank Math, or switch to the core option, which sends every attachment URL to its file. Media uploaded straight to the library has no parent post, so a parent-post redirect has nowhere to send it.

Sources

  1. Changes to Attachment Pages in WordPress 6.4 Make WordPress Core
  2. How to redirect attachment URLs to the media itself Yoast
  3. Should You Redirect Attachment Page URLs? Rank Math
  4. Disable Media Pages WordPress.org Plugin Directory
  5. is_attachment() WordPress Developer Resources

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test