Support » Plugins » Redirect Attachment page to Post page – How To?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Kirk T


    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 as a result. this ‘image1’ is attached to ‘post1’. when the visitor clicks on that image, it should redirect him to

    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.


    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.

    this did’nt help much. anyways thanks.

    @kirk T

    I want to do the same on 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


    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

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