WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Redirect Attachment page to Post page - How To? (14 posts)

  1. Kirk T
    Member
    Posted 5 years ago #

    Is there a way to automatically redirect links to the attachment page back to the post they are associated with?

    I'm using a lightbox effect for galleries, but the problem arises when thumbnail images of a gallery are clicked in an RSS reader. This takes them to the attachment page:

    http://thewalters5.com/red-river-gorge-camping-trip/2009/05/rr1/

    But, I would rather it take them to the post page to use the lightbox effect and keep all comments on the post instead of individual images:

    http://thewalters5.com/red-river-gorge-camping-trip/2009/05/

    I've styled the image attachment page for aesthetics sake, but I would prefer they land on the post page.

    Any suggestions? Thanks.

  2. Kirk T
    Member
    Posted 5 years ago #

    Just replaced entire attachment page template with this:

    <?php wp_redirect(get_permalink($post->post_parent)); ?>

    and it seems to do the job.

  3. bekar09
    Member
    Posted 5 years ago #

    can you point the file name exactly?

  4. Kirk T
    Member
    Posted 5 years ago #

    Do you mean redirect to the actual file, or redirect the file somewhere else?

    Either way, I'm not sure how...this solution works for me since the RSS links to image files seem to go instead to the attachment page...so redirecting the attachment page to the post page has worked for what I need.

  5. bekar09
    Member
    Posted 5 years ago #

    i mean redirecting the attachment(.jpg) to be redirected to the parent post it is attached to.

  6. Kirk T
    Member
    Posted 5 years ago #

    That's what I thought you meant...sorry I can't help with that...

    What's the scenario where you want to do this? Why are people getting to the actual JPG image anyway? There might be another solution depending on the scenario.

  7. bekar09
    Member
    Posted 5 years ago #

    i think you're not getting me. when a visitor searches for an image and reaches my website, i want him to redirect to the post to which the image is attached to.

    for example, google image search gives 'image1' the url of which is http://www.my-website.com/path-to-upload-dir/image1.jpg as a result. this 'image1' is attached to 'post1'. when the visitor clicks on that image, it should redirect him to http://www.my-website.com/post1.html.

    does that make sense?

  8. Kirk T
    Member
    Posted 5 years ago #

    That makes perfect sense...I definitely see the need for that now...

    I'll go back through my notes to see if I ran across any solution for it. I don't remember it, so don't set your hopes too high, but stay tuned...I'll keep you posted.

  9. bekar09
    Member
    Posted 5 years ago #

    waiting for your reply.

    tnx,.

  10. Kirk T
    Member
    Posted 5 years ago #

    Well, I didn't find much. This link below seems to be the only one I bookmarked that might lead to some sort of working solution. I didn't really pursue it since my goal was different than yours, but hopefully this will lead to something. Enjoy.

    http://www.webmasterworld.com/forum92/6212.htm

  11. bekar09
    Member
    Posted 5 years ago #

    this did'nt help much. anyways thanks.

  12. riversatile
    Member
    Posted 4 years ago #

    @Kirk T

    I want to do the same on http://www.riversatile.fr for the same reason.
    But my template for attachment is the file "single.php", this file is already used for all posts, I don't know where do I put the line :
    <?php wp_redirect(get_permalink($post->post_parent)); ?>
    From my understanding I should have a dedicated file for attachment request ??? Then put this line in it ?

    Thanks for your help

  13. Kirk T
    Member
    Posted 4 years ago #

    @riversatile

    Yes, a dedicated attachment page template is what I use, and the only thing in there is that line of code. I only use it for the image attachment template, so just drop a file called "image.php" in your theme directory and have this line in there:

    <?php wp_redirect(get_permalink($post->post_parent)); ?>

    I've been using this for a while now on several site with no problems, so I hope it helps. Let me know if you run into any trouble.

  14. riversatile
    Member
    Posted 4 years ago #

    Yeah !!!!!! It's incredible ! It works ;)

    Thanks Kirk T
    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic