WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Redirect Attachment page to Post page – How To?

[Resolved] Redirect Attachment page to Post page – How To?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Just replaced entire attachment page template with this:

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

    and it seems to do the job.

    can you point the file name exactly?

    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.

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

    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.

    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?

    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.

    waiting for your reply.

    tnx,.

    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

    this did’nt help much. anyways thanks.

    @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

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

    Yeah !!!!!! It’s incredible ! It works 😉

    Thanks Kirk T
    Cheers

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] Redirect Attachment page to Post page – How To?’ is closed to new replies.
Skip to toolbar