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:
Contains this image:
Which is fine, but somehow this image is also exposed as its own URL and “post”:
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:
Attachments are actually a post type, so they take a row in the posts table like a post does, they will always have a URL available, in the same way that posts do to..
16 is the post ID, and like posts they will always be available by a URL like the above. Media files aren’t simply considered files, they have a more content like element to them, in that they have a record in the posts table that corresponds to them, just like a post or page does.
What you’re asking is how to stop the automatic existance of individual attachment URLs for each media item(not really possible because they’re essentially a post type, which means they’ll always be a URL for them).
Here’s a suggestion though, take any template(theme) file, index.php, page.php, archive.php or whatever you like, create a copy and rename it to image.php or attachment.php if you want to target all media. Open the file, remove the loop, save… and load up one of the attachment pages(like the one you provided before)..
My point being, all you need to do is create an attachment template file:
If you wanted to, in theory you could place a redirect into the attachment template so individual attachment views are redirected (or any number of other things you might want to do).
Someone posted just that, an
attachment.php that goes in your
/themes folder to redirect:
<?php header ('HTTP/1.1 301 Moved Permanently'); header ('Location: '.get_permalink($post->post_parent)); ?>