Completely disable ”attachment” pages created by WordPress.
By default, WordPress creates a page for each of your attachments. This is can be undesirable because of two reasons:
Search engine optimization
Attachment pages don’t have any content, except an image, so they provide little value and can negatively affect your SEO because they are so-called thin content. Even worse, attachment pages may in some cases rank higher than your actual content pages which leads to a poor user experience.
Attachment pages can accidentally reserve slugs on your site. Let’s say you upload an image named contact.jpeg, an attachment page
https://example.com/contact is automatically created. If you then try to create a page named Contact, the URL for that page will be
https://example.com/contact-2 which isn’t that great.
How it works
This plugin works by automatically setting all attachment slugs to an unique id, so they won’t conflict with your pages. If an attachment page is accessed, the plugin will set a 404 status code and display the ”page not found” template.
You can also mangle any existing attachment slugs so they won’t cause any issues in the future.
Special thanks to Greg Schoppe for his research and inspiration that helped a lot with developing this plugin.
Support the plugin
Maintaining a WordPress plugin is a lot of work. If you like the plugin, please consider rating it on WordPress.org. You can also support me on GitHub sponsors. Thank you!
If you are interested, you can also check out my other WordPress plugins:
- Install the plugin from your WordPress dashboard
- Activate the Disable Media Pages plugin via the plugins admin page
- From now on, media pages will be disabled and new media items uploaded in the library will get unique id slugs
How to mangle existing attachment slugs?
Go to the Settings ▸ Disable Media Pages ▸ Mangle existing slugs. This will show you a wizard to mangle existing attachment slugs.
Why not just use Yoast SEO? It has a feature to redirect attachment pages to parent
First of all, not everyone uses Yoast SEO. More importantly, while Yoast SEO can fix the duplicate content issue, it does not help with issue of media files reserving slugs for pages.
What if I want to redirect attachment pages to parent page instead?
Instead of displaying a 404 HTTP error, some people recommend you to redirect attachment pages to the parent page instead. I think this can be a good short-term solution if the attachment pages have been indexed by Google and you want to preserve SEO ranking for these URLs. There’s a plenty of plugins on the plugin directory that let you to do that. In my opinion returning the 404 error is the correct long-term solution and if you are launching a new site, it’s best to simply disable these pages so they won’t ever end up in Google index.
What kind of unique id is used?
The unique id is an UUIDv4, without dashes.
Can I restore the attachment page slugs after mangling?
Yes, this functionality is available in version 1.1.0. The attachment slug restoration tool allows you to restore the attachment slugs back to ones based on the attachment title.
Can I find this plugin on GitHub?
Yes, check out the GitHub repository.
Avustajat & Kehittäjät
“Disable Media Pages” perustuu avoimeen lähdekoodiin. Seuraavat henkilöt ovat osallistuneet tämän lisäosan kehittämiseen.Avustajat
“Disable Media Pages” has been translated into 6 locales. Kiitoksia kääntäjille heidän työstään.
Käännä “Disable Media Pages” omalle kielellesi.
Oletko kiinnostunut kehitystyöstä?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
- Fix: Fix typo. Thanks to porg for noticing this!
- Fix: Test in WP 6.1
- Fix: small update to readme
- Breaking change: fixed how the plugin hooks into the
redirect_canonicalaction. Because the plugin didn’t return a value from this filter, this caused the plugin to change default WordPress behaviour (eg. https://example.com/index.php did not redirect to https://example.com/ like with a normal WordPress installation). In this version the filter returns the value which restores this WordPress default functionality. I’m making this a major release because it changes the plugin behaviour, so I recommend testing your site in a development or staging environment before updating your production site. For more information, see this support thread.
- Feature: Improved slug generation logic. Now the plugin checks the slug is in UUIDv4 format before generating a new slug. This prevents slugs from changing when saving a post.
- Fix: Test in WP 6.0
- Fix: Add missing localization string
- Fix: Minor readme updates
- Fix: Optimize acceptance test database size
- Fix: Fix typo
- Feature: Improved plugin code structure
- Feature: Add donate link
- Fix: Readme update
- Fix: Fix issue where the plugin was unable to mangle slugs that contained UUID along with some other text
- Fix: Bump supported WordPress version to 5.9
- Fix: Readme updates
- Fix: Add automated test for slug restore functionality
- Fix: Remove debugging statements
- Fix: Fix typo in readme
- Fix: Minor fix to the icon
- Feature: Add a tool for restoring media slugs back to the original ones
- Feature: Add status page for the plugin which tells you if you have attachments without unique ids
- Fix: Add menu for the plugin under Settings on the WordPress dashboard
- Fix: Update plugin icon
- Fix: Bump supported WordPress version to 5.8
- Fix: Update dependencies
- Fix: Update dependencies
- Fix: Update FAQ
- Fix: Tweak icon
- Fix: Fix issue with deployment
- Fix: Bump tested up to @ 5.7
- Fix: Add acceptance tests
- Change: Add icon
- Fix: Change required WordPress version correctly to 5.0
- Fix: Optimize autoloader
- Change: Release on WordPress plugin directory
- Change: Changes to internal plugin structure
- Fix: Make plugin translatable
- Fix: WordPress 5.6 compatibility, thanks @tnottu
- Initial release