Redirect Attachment page to Post page – How To?
-
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.
-
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.
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
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
- The topic ‘Redirect Attachment page to Post page – How To?’ is closed to new replies.