When doing a bit of Google searching for content on our blog, I noticed to my shock and horror that individual images from the Media Library are somehow generating their own URLs that Google is somehow finding and indexing!
For example this page:
http://blog.stackoverflow.com/2008/08/special-development-team-podcast/
Contains this image:
http://blog.stackoverflow.com/wp-content/uploads/bio-jarrod-dixon.jpg
Which is fine, but somehow this image is also exposed as its own URL and “post”:
http://blog.stackoverflow.com/2008/08/special-development-team-podcast/bio-jarrod-dixon/
This is extremely unwanted!
I checked the Media settings in WordPress and browsed around the Media Library but I can’t figure out a way to disable this behavior. Any ideas?
This thing you are saying is unwanted is just normal functionality under WordPress and it cannot be removed. However there are things you can do to point the unwanted URL to something more usefull.
Here is a forum post on this issue with some interesting fixes and a description on what is happening:
http://wordpress.org/support/topic/disable-attachment-posts-without-remove-the-medias
Someone posted just that, an
attachment.php
that goes in your/themes
folder to redirect:I figured it’s about time i at least tried my hand at wiping out attachment pages.
Here’s my first shot at it…
Removes the attachment rewrites, updates the attachment links to point at the attachment file(instead of it’s permalink), removes the attachment query vars and also removes the ability to link attachments to the now non-existant attachment permalink.
Open to critique. 🙂
You can do a 301 redirection for attachments to their parent’s page like this:
Yoast’s SEO plugin has “Redirect attachment URL’s to parent post URL” under permalinks. I used this option to resolve the issue. The plugin is amazing.
This is a related answer from a related question: Disable attachment pages completely
This method modifies rewrite rules.
https://wordpress.stackexchange.com/a/271089/71608