Google is indexing wordpress attachment pages

Just add this to your functions.php or plugin.

add_action( 'template_redirect', 'attachment_redirect', 1 );
/**
 * Redirect any attachment page to their parent with 301 redirection
 */
function attachment_redirect() {
  global $post;
  if ( is_attachment() AND isset( $post->post_parent) AND is_numeric( $post->post_parent ) ) {
    wp_redirect( get_permalink( $post->post_parent ), 301 );
    exit();
  }
}

Leave a Comment