[resolved] Disable 'attachment' posts without remove the Medias (17 posts)

  1. riversatile
    Posted 5 years ago #

    Hi All,

    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 ;)

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    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.

  3. riversatile
    Posted 5 years ago #

    Yes, it's the case !!! This is why I don't understand !

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    Sorry? Don't understand what?

  5. riversatile
    Posted 5 years ago #

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

  6. esmi
    Forum Moderator
    Posted 5 years ago #

    WordPress remembers the last setting(s) used.

  7. riversatile
    Posted 5 years ago #

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

  8. riversatile
    Posted 5 years ago #

    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 !

  9. Mark / t31os

    Posted 5 years ago #

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

  10. riversatile
    Posted 5 years ago #

    Sorry, What mean "remove the loop" ?

  11. Mark / t31os

    Posted 5 years ago #

    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.

  12. riversatile
    Posted 5 years ago #

    ...I've not found any solution

  13. riversatile
    Posted 5 years ago #

    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

  14. mataga
    Posted 5 years ago #

    Try using a plugin called Redirection, where you can make 301 redirections that search engines will obey.

  15. acerothstien
    Posted 5 years ago #

    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!

  16. Joanne
    Posted 5 years ago #

    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.

  17. PerryRoper
    Posted 4 years ago #

    header ('HTTP/1.1 301 Moved Permanently');
    header ('Location: '.get_permalink($post->post_parent));

    Put that in your themes attachment.php

Topic Closed

This topic has been closed to new replies.

About this Topic