Jeepy
Elite Member
- Jan 22, 2013
- 1,994
- 1,975
As we all know Yoast fucked up your sites a little bit by allowing to index attachment pages. As I don't use Yoast because I do not like when someone messes with my SEO, my attachment pages were indexed anyway, so then there is a permanent solution how to redirect your image attachment page to original post via 301:
1. Go to your theme files (if you have a child theme, go to that folder)
2. Create image.php file
3. Add this code:
4. Check your Google Webmaster indexed pages, find attachment page and check if it is redirecting correctly.
5. Wait few days or weeks so Google can remove those useless thin content pages from SERPS.
1. Go to your theme files (if you have a child theme, go to that folder)
2. Create image.php file
3. Add this code:
Code:
<?php
global $post;
if ( $post && $post->post_parent ) {
wp_redirect( esc_url( get_permalink( $post->post_parent ) ), 301 );
exit;
} else {
wp_redirect( esc_url( home_url( '/' ) ), 301 );
exit;
}
4. Check your Google Webmaster indexed pages, find attachment page and check if it is redirecting correctly.
5. Wait few days or weeks so Google can remove those useless thin content pages from SERPS.