I recently noticed that the attachment pages of my friend's website appears in Google search. I applied the Yoast plugin solution to redirect those pages to post itself but I want to guarantee that they won't appear in Google search. Can yoast plugin do that or for example, is this option better: adding

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

to image.php


You can verify that Yoast does indeed 301 (permanently) redirect attachment pages by viewing the Media Library and copying one of the attachment page URLs into a HTTP header check tool. (Yes, they do.)

Once everything is 301 redirected, it will eventually be updated in Google's index. This can take some time, so you could use Webmaster Tools to ask Google to remove those URLs one at a time if you like.

If the image.php you're talking about is a Core file, modifying Core is never a better option. If it's in a theme, likewise you shouldn't modify a theme directly - you would create a child theme and make changes there, so your changes don't get lost when the parent theme updates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.