The post was last updated on 4/3/2018
When you upload a media file, like an image or a video, and attach it to a post/page, WordPress will create its own attachment page, just like a normal page.
The bad news is that this page will be published by default, which means that it can be accessed by the general public.
Most of you will want to prevent that from happening, either because you have a media file that you don’t want to be accessed by everybody, or because the attachment page looks pretty bad because the theme developers didn’t pay any attention to it.
Here’s an example of how it looks like:
It looks pretty weird, no? Just the file, its title, your sidebar, comment area…
Therefore, in this article, I’ll show you how to disable the attachment pages in WordPress with one of these two plugins.
Disable media attachment pages with the “Yoast SEO” plugin
For those of you who are using the Yoast SEO plugin – and all of you should use it because it will make your life so much easier, not just for SEO; it’s a must-have plugin – you just need to activate an option.
- Go to SEO -> Search Appearance;
- Select the Media tab;
- Select the Yes option under Redirect attachment URLs to the attachment itself?;
- Click the Save Changes button.
The versions prior to 7.0, would have redirected the attachment page to the parent post.
Starting with Yoast 7.0, it will redirect the attachment page to the media file itself, which is much better.
Disable media attachment pages with the “Attachment Pages Redirect” plugin
For those of you that don’t have Yoast installed, and don’t want to have it either, especially for just one feature, then install Attachment Pages Redirect, which handles just that.
Once activated, it will perform a 301 redirect (permanent redirect) from the attachment page to the parent post, if the media file is attached there.
If it’s not attached, then it will perform a 302 redirect (temporary redirect) to your homepage.
The plugin doesn’t have any settings. You just have to activate it, that’s it.
That’s a wrap
Hope you found the post useful!
Don’t forget to share it with your friends!
If you have any questions or thoughts, drop a comment, contact us or message us on Facebook.
It works but the following page has a normal url like ?page_id=647 and not the permalink like /pagename/. Any ideas?
I didn’t quite understand what you’re trying to say.
Thanks for useful information.
Thank You, This post is very useful! I have implemented the same on my blog.
But You can still go to these media pages if you know their URL. Is it possible to completly turn off creating these pages?
Nope, you can’t. You can go to the files themselves (e.g.
https://example.com/wp-content/uploads/2017/09/image.png
), but not the attachment pages, because you’ll get redirected.Not if the image was added to the media lib but not used in a post it won’t.
My images was indexed in Google Search. I selected the Yes option under Redirect attachment URLs to the attachment itself?
But how to solve this situation with indexed old pictures?
Using that option won’t prevent Google from indexing the actual images, unless you just upload them without actually adding them anywhere on your website (e.g. posts or pages). If you add images somewhere on your site, then they will automatically get indexed by Google. To prevent images from appearing in Google’s search results, follow this guide – https://support.google.com/webmasters/answer/35308?hl=en.
Hello , thanks for your help.
Unfortunately google indexes like 2000 pages of media, precisely like the Locomotive example.
I must have turned that Yoast option off on by mistake, so it happened. This was 3 weeks ago. Now it’s been a couple of days that I set it back ON.
Is this all I should do? The media pages are still indexed, do you think they’ll be removed automatically? I also resent the site for indexing on webmaster tools.
Many thanks will read your site again, you saved me!!
Hello! Setting it back on won’t remove the pages that were already indexed by Google. Usually, when 301 redirections (permanent redirects) are in place for quite some time, Google will automatically start removing the pages that are being redirected, from the search results, because it thinks that they’ve been moved permanently, therefore there’s no need in showing them. If you wish to remove those that appear in the search results, try this – https://support.google.com/webmasters/answer/1663419
Thanks a lot!
I don’t understand all this nonsense.
I mean at the end of the day, these attachment pages serve no purpose at all and shouldn’t be indexed by Google.
Whats wrong with just setting a
Disallow: ?attachment_id=
….within your robots.txt
Disallowing something in robots.txt doesn’t mean that search engines won’t crawl and index it. It’s not a sure thing. You can read more about the robots.txt limitations here – https://support.google.com/webmasters/answer/6062608?hl=en&ref_topic=6061961
HI.
Everyone can copy the photos when they search by google! wordpress.
How do i solving the problem?
how can i protect the photos in google
Hello! You can’t. Anyone can save/copy images that are indexed by Google.
Hi,
How about if we upload image from media not upload from articles or pages. Its also auto create attachment page and more dangerous because the attachment image page url at root our domain such as oursite dot com/ this-is image-title-uploaded/ ?
Thanks in advance
Hello!
As long as the post or page is published, the media files on that post or page will have Media Attachment Pages created for them, regardless where you upload them from.
If the post or page is saved as a draft, for example, then the media files on that post or page won’t have a an attachment page created that’s public.
I dont get why: “The versions prior to 7.0, would have redirected the attachment page to the parent post.
Starting with Yoast 7.0, it will redirect the attachment page to the media file itself, which is much better.”?
I want my pictures get more views of the actual post, what’s the use of just the view of the picture attachment? Is there a way to do it the old way, were it redirected the attachment page to the parent post?
Yoast offers an explanation here, in the “What do attachment URLs do anyway?” section.
The reasons are:
1. When you uploaded images that were not attached to posts, but to other parts of your site, such as the logo or site icon, the redirection would not take place since it only applied to posts.
2. If you attached the same image on multiple posts, then you wouldn’t know where it would redirect exactly.
If you liked the old method, then disable the option from Yoast and use the plugin I mentioned. The plugin redirects to the parent post.
Thanks a lot for this informations. Should we have any solution to remove the attachment URL from the site? I removed the attached image but URL is still there. Any solution to fix?
That URL will return a “404 Page Not Found” after deleting the image. Basically, those URLs don’t exist anymore, but as any URL that doesn’t have content (pages, posts, etc.) assigned to it, it will return 404. For example, you can type a random URL using your domain (e.g.
https://example.com/123
) and it will return a 404 error, but that doesn’t mean that the URL exists somewhere on your site and can be deleted.Redirects do not disable anything! They do just that – redirect.
From a technical stand point, yes. For the general public is basically disabled. They can’t access and see it.
Thank you! We were getting comments.. comments! on the attachment pages like \”where do I buy this?\” and were wondering how it got indexed as an attachment. So strange. I have yoast and that setting turned off but somehow a few got through. The plugin solves that issue. Good post thank you.