How to Disable WordPress Attachment Pages

Quick update on this topic as of 2024: WordPress 6.4 has introduced a notable change in how attachment pages are handled. For all new WordPress installations, attachment pages are fully disabled by default.

This only affects new installs – meaning users who installed their site recently and did so on WordPress 6.4 or newer from the start will have their attachment pages disabled.

However, if you’ve been running your site for quite a while and have just updated to WordPress 6.4 now, this won’t affect you. What this means is that for users like that, you still need to take action on your attachment page settings manually.

Below, I show you want you can do about that exactly:

How to test if you have attachment pages enabled

Go to your WordPress media library, click on any media file and look for this link:

View attachment page in WordPress
  • If the link is there, you click on it, and you get taken to a standard WordPress page with just the attachment file embedded, then you obviously have attachment pages enabled.
  • If the link is not even there, or it says “view media file” instead, then you have attachment pages disabled already.

Here’s why you should disable the attachment pages entirely

Previously, WordPress automatically created an attachment page for each file uploaded. For example, let’s say you create a post and add three images to it. WordPress then automatically creates four URLs – three for the images, and one for the original post.

This feature, while well-intentioned, often led to unnecessary pages that cluttered your site and search engine results without adding value.

Disabling attachment pages streamlines content management and improves the overall quality of search results for users and site owners alike. A small but impactful adjustment to keep in mind as you work on your WordPress site!

Here’s how to disable attachment pages if you still have them

Previously, most people used plugins for this. SEO plugins in particular have a lot of features built-in to do various things with attachment pages, but you can pretty much ignore all that in 2024.

Instead, the fastest way to disable attachment pages and end up with a clean site structure is to go to the options.php page of your site and do a quick edit there.

Don’t worry, though, you don’t have to edit the file by hand.

Instead, go to your wp-admin and simply add “options.php” at the end of your URL. For example:

https://YOURSITE.COM/wp-admin/options.php

⚠️ Warning, this is technically an important file for WordPress’ overall operation. If you’re not 100% comfortable here, it’s advisable to make a backup of the site beforehand. Here’s some advice on backups.

Here’s what you’ll see (the beginning of that page):

options.php page

Find the line that says wp_attachment_pages_enabled:

disable WordPress attachment pages
  1. Simply change 1 to 0 there.
  2. Click on save changes.

What this does:

  • As soon as you make this change, the attachment pages will be disabled, and all current attachment pages will be redirected to the raw URL of the attachment itself. (This is good, this is what you want).

That’s it! Done and done. 👌

Let me know if you have any further questions about this process.

Yay! 🎉 You made it to the end of the article!

10 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Meetu Sehgal
July 7, 2018 10:00 pm

Thanks a ton… Helpful explanation and solution.

Ankit Sharma
April 17, 2018 4:59 am

I think Advanced >> Permanent links are gone with version 7.2 they now only have redirect to image instead of post which is so useless. How to do that with the latest version now.

dare2gocom
December 22, 2017 5:09 pm

The catch with WordPress ‘unattached media items’: every image you integrate in a post via a gallery (like Jetpack’s Tiled Galleries’) shows in the media library as “unattached”! You have to be really careful not to remove such files via a plugin (as some people suggest).

Priya K
March 17, 2018 2:45 am
Reply to  dare2gocom

Like you said, the redirect fix is to be used with care. The recent update released on 6th March alters the way the plugin handles unattached media items as well.

Havi Goffan
March 18, 2018 2:12 am
Reply to  Priya K

Yes, Priya. This is quite a nightmare. I have a website packed with images. I need those images to rank but as images. As it was before. The rest has me extremely confused. What happens if one image is attached to two different articles? Or unattached like logos? Anybody shedding some light here would be truly appreciated.

Max Theiss
December 16, 2017 3:57 pm

But an extra plugin?
simply into the function. php

##

function mytheme_redirect_attachment_page() {
if ( is_attachment() ) {
global $post;
if ( $post && $post->post_parent ) {
wp_redirect( esc_url( get_permalink( $post->post_parent ) ), 301 );
exit;
} else {
wp_redirect( esc_url( home_url( ‘/’ ) ), 301 );
exit;
}
}
}
add_action( ‘template_redirect’, ‘mytheme_redirect_attachment_page’ );

##

Diego!
March 5, 2018 11:21 pm
Reply to  Max Theiss

Max! Many thanks for your knowledge.
You save me!
I don’t know why but with the Yoast SEO does not work and neither the PHP code (Make a loop)
Thanks

Pixel Web Soft
March 15, 2018 3:53 pm
Reply to  Max Theiss

As simple as that! Saved my day 🙂

Ankit Sharma
April 17, 2018 5:09 am
Reply to  Max Theiss

Its Redirecting to Home page. Can we redirect it to post page itself. If yes can you please help me with the code.

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!