Redirect Unattached Images

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 http://website.com?attachment_id=32

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:

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.

Download Redirect Unattached Images

4 Comments

  1. 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.

        1. 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.

Leave a Reply

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