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:
- Create a new file called “image.php” or delete everything on your current image.php file (if present)
- 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!









Doing that can cause a problem in the google image serp?
NO i just redirect links not .jpg file source
You sure?
302 redirects will cause search engine crawlers to treat the redirect as temporary and not pass any link juice (ranking power).
Ok but google can crowl image correctly?
The crawler see the image in the post but can’t but when try to see it in original are redirected to the same post, and can crawl only the little pic and not the original.
i don’t think except if you have a picture or wallpaper blog !
Yes, But the crawler can index the image?