Redirect Attachment Image File to Parent Post in WordPress

      

How to Redirect Attachment Image File to Parent Post in WordPress many people searching for this including me but we can’t prevent or disable Google to index these files just move to original post or page.I noticed multiple “image pages” indexed on Google. Whenever you add an image to your post it automatically attaches a link to the image that goes to a blank post (WordPress stores attached image data as posts in the db) with nothing but that image.

The issue is that these pages are virtually pointless as they have no content. You are better off linking to your actual image itself if you want people to be able to click and see a large version.

So after a bit of browsing a found a really good solution to help you “disable” these image pages and bring the page rank back to your main post. Technically it won’t disable the image attachment pages, but it redirects the page back to the primary post.

Image Attachment Pages Using A WP Redirect:

  1. Create a new file called “image.php” or delete everything on your current image.php file (if present)
  2. Insert the code below in your image.php file using a text-editor and upload to your theme’s directory.Or you Download file here
<?php wp_redirect(get_permalink($post->post_parent)); ?>

Paste it in Root> wp content> Template> <your theme> Paste here.

Now when you refresh your image attachment page it should redirect to the original post Enjoy!

About

Sandeep who always wants to explore and share interesting Tips, Tricks, Tutorials, Guides and More. Catch him on Twitter, Join Facebook Fan Page. Subscribe to wRock feed via RSS or EMAIL to receive instant updates.

comments

  1. Paul says:

    Doing that can cause a problem in the google image serp?

  2. Paul says:

    Yes, But the crawler can index the image?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Human Verification: In order to verify that you are a human and not a spam bot.