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