Skip to content

How to Disable Image Attachment Pages in WordPress (3 Easy Methods)

Flat window icon with image and toggle beside the title How to Disable Image Attachment Pages

To disable image attachment pages in WordPress, redirect each attachment URL to its parent post or to the image file. An SEO plugin setting, a short PHP snippet or the core wp_attachment_pages_enabled option can do it. Sites installed on WordPress 6.4 or later already have them off.

An attachment page is the page WordPress builds for every file you upload. It shows the image and little else. We checked each method in this guide against the WordPress core dev note and the Yoast, AIOSEO and Rank Math docs in October 2026.

First you will check whether your site already has them off. Then you will see three fixes: SEO plugins, a PHP snippet and the WordPress 6.4 option.

Why Disable Image Attachment Pages in WordPress?

Although WordPress generates one attachment page for each media upload, these pages often:

  • Create “Thin Content”: Attachment pages have little more than the image and a caption. The WordPress 6.4 dev note on attachment pages says these pages still get indexed and sometimes rank, which gives searchers a poor result.
  • Duplicate Content Issues: When an image appears in both the original post and the attachment page, search engines are not able to figure out the main URL. Links and signals get split between the post and the attachment page.
  • Reduced Crawl Efficiency: The search engine crawlers might skip the main content of your site if they index many image pages that contain little information. Crawl time spent on them is time not spent on your real pages.
  • Poor Visitor Experience: A visitor who lands on a page with one image and no context often leaves.
  • Reserve Unnecessary URL Slugs: Every attachment page has its own URL. This can block the use of that slug for important content, like posts or landing pages.

Check If Your Site Already Has Attachment Pages Off

Since WordPress 6.4, new installs have attachment pages off by default. They redirect to the file URL, while sites upgraded from an older version keep them on. Check the wp_attachment_pages_enabled option first, because only an older site needs a fix.

The WordPress 6.4 dev note on attachment pages gives the rule. New sites get the value 0 and upgraded sites get 1. Check it in two ways:

  • Open an attachment URL: Visit https://yoursite.com/?attachment_id=123 with the ID of any image from your Media Library. If the browser lands on the image file, attachment pages are already off.
  • Read the option: As an admin, open yoursite.com/wp-admin/options.php and find wp_attachment_pages_enabled. A value of 0 means off and 1 means on.

If the value is 0 and you only want the default redirect to the file, you are done. Use one of the methods below to send attachments to their parent post or to turn them off on an older site.

How to Disable Image Attachment Pages in WordPress: 3 Methods

You can disable image attachment pages in WordPress with an SEO plugin setting, a PHP snippet or the core option from WordPress 6.4. An SEO plugin is the easiest choice if you already run one. The snippet gives you a parent-post redirect without a plugin, and the core option needs no code at all.

1. Disable Image Attachment Pages: Using SEO Plugins

You can easily disable image attachment pages in WordPress by taking advantage of widely used SEO plugins such as Yoast SEO or All in One SEO (AIOSEO). These plugins redirect image attachment pages to their parent posts or to the media files.

1. Yoast SEO

Yoast SEO is a popular plugin that provides a feature of redirecting attachment URLs to the actual media file. This is a very simple tool to disable image attachment pages in WordPress.

Steps
  • Navigate to the Plugins section in your WordPress dashboard and then to Add New.
  • Search for the plugin name (Yoast SEO plugin) and click on Install Now to install the plugin.Yoast SEO plugin card with the Install Now button highlighted
  • Then activate the Yoast SEO plugin by clicking on the Activate button.Yoast SEO plugin card with the Activate button highlighted
  • Once the plugin is activated, go to Settings of the plugin and then Media Pages under the Advanced option.Yoast SEO settings with the Media pages item under Advanced highlighted
  • Make sure the Enable media pages toggle is off. The Yoast media pages docs say it is off by default. Attachment URLs then redirect to the image file itself.Yoast SEO Media pages settings with the Enable media pages toggle switched off

2. All in One SEO (AIOSEO)

You can also disable image attachment pages in your WordPress site using the AIOSEO plugin. This plugin offers a simple method for handling attachment page redirects.

Steps
  • Simply navigate to Plugins followed by Add New the same way you did before.
  • Search for the AIOSEO plugin and click on Install Now.All in One SEO plugin card with the Install Now button highlighted
  • Don’t forget to activate the plugin by clicking on Activate.All in One SEO plugin card with the Activate button highlighted
  • Navigate to the SEO Settings of the AIOSEO plugin.All in One SEO menu group in the WordPress dashboard highlighted
  • Then, navigate to the Search Appearance option.All in One SEO menu with the Search Appearance item highlighted
  • From there, click the Image SEO tab.AIOSEO Search Appearance screen with the Image SEO tab highlighted
  • Under Redirect Attachment URLs, select the Attachment Parent option.AIOSEO Image SEO tab with Redirect Attachment URLs set to Attachment Parent
  • Finally, click Save Changes.AIOSEO Attachment Parent option selected with the Save Changes button highlighted
  • This setup redirects attachment pages to their parent post, improving user experience and search engine optimization.

3. Rank Math SEO

Rank Math has a Redirect Attachments switch that sends each attachment page to the post it was uploaded to. The Rank Math redirect attachments guide gives this path:

  1. Go to Rank Math SEO > General Settings > Links. As of October 2026 this switch is already on by default and needs no Advanced Mode.
  2. Check that Redirect Attachments is on.
    Rank Math Links settings with the Redirect Attachments switch turned on
  3. Set Redirect Orphan Attachments for files not attached to any post. It defaults to your homepage, and a blank field leaves those pages live.
  4. Click Save Changes.

2. Disable Image Attachment Pages: Adding Custom Code

A short PHP snippet can redirect every attachment page to its parent post, or to the file when there is no parent. Add it to a child theme or a code snippets plugin. Code added to a parent theme’s functions.php is lost when the theme updates.

Steps

  • Go to Appearance > Theme File Editor with your child theme active. On a block theme the editor sits under Tools > Theme File Editor.Theme File Editor with the child theme functions.php file open and the redirect code added
  • Open the child theme’s functions.php file under Theme Files.Theme File Editor with the child theme functions.php file highlighted
  • Insert the following code and click on Update File.
function dd_redirect_attachment_pages() {
	if ( ! is_attachment() ) {
		return;
	}

	$attachment_id = get_queried_object_id();
	$parent_id     = wp_get_post_parent_id( $attachment_id );

	if ( $parent_id && 'publish' === get_post_status( $parent_id ) ) {
		$target = get_permalink( $parent_id );
	} else {
		$target = wp_get_attachment_url( $attachment_id );
	}

	if ( $target ) {
		wp_redirect( esc_url_raw( $target ), 301 );
		exit;
	}
}
add_action( 'template_redirect', 'dd_redirect_attachment_pages' );
  • The code sends each attachment page to its published parent post. A file with no parent goes to the file URL from wp_get_attachment_url().

3. Disable Image Attachment Pages: Using WordPress 6.4 Feature

WordPress 6.4 added the wp_attachment_pages_enabled option. There is no screen for it. You change it on the hidden all-options page. Set it to 0 and attachment pages redirect to the file URL.

Steps

  • Type your site address followed by /wp-admin/options.php in the browser.WordPress options.php page with the wp_attachment_pages_enabled row highlighted
  • Then look for wp_attachment_pages_enabled and set its value to 0.WordPress options.php page with wp_attachment_pages_enabled set to 0
  • Lastly, click on Save Changes to save all the changes.
  • Attachment pages now redirect to the media file URL.

Conclusion

Disabling image attachment pages in WordPress removes one thin page per upload. New sites since 6.4 already have them off. Check the option before you add anything.

Quick recap:

  • Thin-content pages: These pages add little for readers and use crawl time that your real pages could get.
  • Redirecting attachment URLs: A 301 redirect points any links to old attachment pages at the post or the file.
  • Choose your approach:
    • If you are a beginner, use the setting in Yoast, AIOSEO or Rank Math.
    • If you want more control, lightweight (custom) PHP may help you.
    • If you want no plugin and no code, set the WordPress 6.4+ core option.

Once a method is in place, run these checks:

  • Test the redirect: Open a few old attachment URLs and confirm each one lands on the post or the file.
  • Resubmit your sitemap: Regenerate it and submit it in Google Search Console.
  • Watch indexed pages: The attachment URLs should drop out of the Pages report in Search Console over the following weeks.
  • Check new uploads: Open the attachment URL of a newly uploaded file now and then.

One setting or one snippet keeps every future upload from creating a thin page.

Frequently Asked Questions (FAQs)

Q1. What happens to image URLs after disabling attachment pages?

When you disable or redirect image attachment pages, WordPress sends visitors and bots to the direct media file or the parent post. Most methods use a 301 redirect, preserving link equity while eliminating low-value pages.

No redirects (plugin/code) ensure links remain functional. They either point to the parent post or the media file directly. Make sure your theme or gallery plugin can link parent posts. This is important for lightbox settings.

Q3. Is it possible to disable attachment pages without using a plugin?

Yes. You can do this by utilizing the PHP snippet in your functions.php file. You can also disable attachments by using the WordPress 6.4 toggle (which involves setting wp_attachment_pages_enabled = 0 in options.php).

Q4. Does disabling them affect PDF or video attachments?

Yes. The snippet, the core option and the plugin settings act on every attachment, not only images. PDFs, videos and audio files redirect the same way.

Q5. Do I need to regenerate my sitemap after disabling attachment pages?

Yes. After you have set up your redirects, you should regenerate your sitemap. Then, you will want to submit it again using SEO plugins or Google Search Console, as this will help to remove the old attachment URLs. This is also helpful because it makes diagnostics quicker as it allows Google to re-index/bump the URLs quicker, which has a positive knock-on effect for your SEO.

Yogesh Rude
Yogesh Rude

Yogesh Rude is an SEO and content writer at DevDiggers who focuses on eCommerce visibility and on-page optimization. His guides cover the SEO decisions WooCommerce store owners face most often, including product page structure, metadata strategy and how search engines interact with site content.

Leave a Reply

Your email address will not be published. Required fields are marked *