I need some help… I hate that ‘attachment’ page is created for each image of my gallery in my posts !
For exemple, this post : http://www.riversatile.fr/2010/04/18/lost-saison-6-photos-promotionnelles-episode-14
It contains 1 gallery, but for each image in the gallery, I notice there is 1 ‘attachment’ post by image !!! See here : http://www.riversatile.fr/2010/04/18/lost-saison-6-photos-promotionnelles-episode-14/promo-lost-S06E14_06/
I understood that WordPress create himself a new post for each media added into the Media Library, but here my question (I have not found any similar topic/solution) :
How can I disable ‘attachment’ posts (for each image/media) without remove/empty the WordPress Media Library ???
Thanks for your support 😉
When inserting individual images, ensure that the Link is set to File Url.
When inserting a gallery, ensure that “Link thumbnails to” is set to Image File.
Yes, it’s the case !!! This is why I don’t understand !
– Each image URL is already set to file URL
– Thumbnail are already linked to image URL, instead of the ‘Page’
So there is something wrong somewhere…
Here is my gallery :
[gallery link="file" columns="4" orderby="title"]
It’s linked to “File”, and not “Attachment page”
And in my gallery advanced configuration, each image is linked to itself complete URL (http://my.site/image.jpg)
So I don’t understand why attachment page exists and are indexed by google…
from my understanding, when we add a media, wordpress create automatically an entry into Media Library, the object (direct URL) is linked to itself and linked to a post or ‘attachment page’, it seems it’s impossible to prevent wordpress to create this page and prevent google indexing these attachment page !
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).
Like any other template file, in order to show the post(or in this case the attachment information), your theme’s template file has some code that looks like this…
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- HTML etc... etc.. --> <?php endwhile; ?> <?php endif; ?>
If you remove that loop, you don’t display that post(attachment in this case). You could replace that code with a redirect, an error message, an image, or whatever you want. You can’t realistically remove the attachment URLs, but you can change what gets shown if someone queries an individual attachment URL.
I’ve found solution into another old topic…
The only thing I can do is to redirect every attachment page/posts to its parent URL :
1) Create a new PHP file
2) Paste this line in it :
<?php wp_redirect(get_permalink($post->post_parent)); ?>
3) Save the file as “image.php”
4) Upload it into your theme folder
That’s it !
Now, every request to http://www.riversatile.fr/2010/04/18/lost-saison-6-photos-promotionnelles-episode-14/promo-lost-S06E14_06/ redirect to its parent URL : http://www.riversatile.fr/2010/04/18/lost-saison-6-photos-promotionnelles-episode-14/
But it doesn’t disable indexing by Google ! Sorry
Try using a plugin called Redirection, where you can make 301 redirections that search engines will obey.
Riversatile, thanks for the tip ..it worked perfect for me…as far as google indexing the images It doesent bother me…just more hooks in the water! Thank Again!
Riversatile, thanks for posting your solution.
Mark / t31os, very helpful to have this explanation of attachments as post types. With my theme, WordPress 3.0.4 was overwriting my links to the file and putting in links to the attachment. Not good.
Great to have this solution.
- The topic ‘Disable ‘attachment’ posts without remove the Medias’ is closed to new replies.