Redirect loop for post attachments
-
I am running the Twenty Eleven theme. By using Yoast his SEO Plugin I tried to redirect post attachments to their parent page. I did this because I did not want Google indexing my post attachments (images) which at the moment is the case when looking for my website in google.
However, when clicking on the images themselves in the post, they do indeed redirect, but when I try to access the post attachment through google search or by putting the url in the address bar, I get stuck in a redirect loop.
What can I do about this? I have recently lost my positions for keywords in the serps, and I am afraid this might have been causing it. Tons of image posts going round google, that were not even accessible.
p.s.
It also happens when I put this in the image.php<?php wp_redirect(get_permalink($post->post_parent)); ?>
-
I don’t see a closing PHP tag, so I am not sure you provided all of functions.php in that pastebin. Please check and try again, as my intent is to add the needed function code.
there is no closing php tag! That is all I have in there. Im guessing that is a problem:)
I have provided the details in the email
Got it and fixing now. I believe the issue is related to your using a child theme. Should have it sorted out soon.
Working on it. Should have it fixed in a jiffy.
haha ok. Do you think that the child theme might also be reason that the 301 redirection to the parent post was not working in the first place?
Well, I feel pretty stupid for forgetting that the Twenty Eleven theme uses an image.php file to show image attachments, rather than attachment.php.
Fixed now. You can turn your caching plugin back on.
I added a file named header-image.php and updated image.php to use it, in your Twenty Eleven theme folder. I also removed attachment.php and header-attachments.php, as those files do nothing.
Note that if you update the Twenty Eleven theme, these changes may be overwritten. So download header-image.php and image.php, put them in a safe place, and consider uploading them again if the tag stops working in the future.
Forget what I said about the child theme. It doesn’t seem to be affecting your site at all.
Ah ok, happens to the best of us! Guiding me through the process reguires intelligence and patience, and you demonstrated you have both! So I can only be very grateful!
Ill put these two files in a safe spot.
Thanks so much for taking the time to have a look at it, have a nice evening!
The topic ‘Redirect loop for post attachments’ is closed to new replies.