Yesterday I was auditing backlinks for a few websites and I noticed something interesting. The site I was looking at had 100s of links from a site with URLs like
At first I wasn’t sure why so many attachment pages were showing up without any kind of permalink structure because the site in question had permalinks enabled. After a bit of digging, I realized they were being created by unattached images in the site’s media library.
In this case, it wasn’t really a big deal because the links were legitimate, nofollowed credit links, but It made me wonder. How many WordPress sites out there have 100s or 1000s of unattached image pages just floating around for no reason?
I ran a quick Google query using one of my favorite search operators and the results were pretty interesting:
Here’s a fun search query: https://t.co/1EvJmVmeZo So glad WordPress generates attachment pages for unattached images. Super useful.
— Rob Neu (@rob_neu) April 22, 2015
I’m sure there’s probably a good reason why this is the default and maybe there is some value in having these pages, but I can’t really think of what it would be. Regardless of why they exist, I definitely don’t want them on my website.
The main issue with WordPress creating all of these useless pages is that having a lot of thin content on your site can chip away at the overall quality score of your domain.
Generally speaking, you don’t want any useless pages showing up in Google’s index. I’d definitely consider these pages useless and I’d recommend getting rid of them if someone asked me about it. I wouldn’t put this at the top of my SEO concerns list but it’s really easy to fix so I decided to write a quick plugin.
So What Does the Plugin Do Exactly?
The way the plugin works is it fires an action on the
template_redirect hook to perform a WordPress redirect on any attachment pages which aren’t associated with a page or post.
Whenever a user or a search crawler lands on one of these pages, they are instantly redirected to the site’s home page. This effectively removes the unwanted pages from your site and eliminates any potential SEO problems they could be causing.
There’s also a filter in the plugin thanks to a suggestion by WordPress legend Andrew Norcross which lets you change the redirect location to somewhere other than the site’s home page.
Redirect Unattached Images is currently available on the WordPress plugin repository. You can download it using the button at the bottom of this post or by searching for “Redirect Unattached Images” in your WordPress plugin installation dashboard.
If you have any questions about the plugin or have any suggestions for other plugins let me know in the comments or open up an issue on the GitHub repository.
If you find the plugin useful, I’d really appreciate a 5 star rating on WordPress.org.
I’m using Yoast’s WordPress plugin for this as I’m assuming the Redirect attachment URL’s to parent post URL setting of their plugin also takes care of this particular part of the attachments page issues.
It doesn’t. With that setting enabled, unattached images are left as-is because they have no parent to redirect to.
For demonstration purposes, I’ve disabled my plugin on this site while Yoast is still enabled and the setting you’re talking about is turned on.
This “logo” image isn’t attached to anything: http://robneu.com/?attachment_id=24 but this image is attached to this post: http://robneu.com/redirect-unattached-images/redirect-unattached-images-2/
Gotcha. Odd thing though. Very unexpected behaviour on WordPress’ part.
Yeah, it’s definitely a head-scratcher. I dunno if it’s something that should be fixed in core or not, but I don’t really follow core dev very closely.
I honestly try to avoid trac as much as I can. If you or anyone else feels like submitting a ticket about it, please feel free.
Rob, I know this article is almost three years old but I was hoping that you could answer a question for me. I am running the latest version of WordPress 4.9.4 and your plugin is redirecting unattached images to my homepage like you designed it to do.
My question is:
When I post a gif on Facebook, I know that FB loads it into their system. With your plugin redirect, once the animated gif appears on someone’s computer and they click on the lower area, shouldn’t they be redirected to my homepage instead of seeing the gif playing on my URL? Even still images do not redirect to my homepage when clicked on.
In my dashboard>media library if I click on View it sends me to my homepage. Why doesn’t it do that when images appear elsewhere on the internet?
The plugin is only designed to redirect the attachment page that WordPress generates. It won’t redirect the raw image URL, as that would break a lot of things for a lot of people.
Comments are closed.