Family Encyclopedia >> Electronics

How to Disable WordPress Image Attachment Pages and Redirect to Parent Posts

As experienced WordPress developers and SEO specialists, we've helped countless sites optimize their structure by disabling unnecessary image attachment pages. By default, WordPress generates individual pages for every media file uploaded—images, videos, PDFs, and more. This works well for photographers but creates clutter and poor user experiences for most sites. Beginners often link images to these pages accidentally, leading to unstyled pages since many themes lack dedicated templates. Popular images might even rank in Google, sending traffic to isolated pages instead of your content. In this guide, we'll show you proven methods to disable these pages and redirect visitors to the original post.

If you're using the Yoast SEO plugin—our top recommendation for WordPress sites—head to SEO » Search Appearance » Content Types. Enable the option “Redirect attachment URLs to the parent post URL”. This seamlessly redirects users from attachment pages back to the parent post.

How to Disable WordPress Image Attachment Pages and Redirect to Parent Posts

Not using Yoast? Install the lightweight Attachment Page Redirect plugin. Activate it, and it automatically redirects attachment URLs to the parent post (or homepage if no parent exists). No configuration needed—plug-and-play simplicity we've tested across hundreds of sites.

Prefer code for full control? Create or edit image.php in your active theme's directory. Add this at the top:

<?php
wp_redirect( get_permalink( $post->post_parent ) );
exit;
?>

Save and upload. Users hitting attachment pages will now land on the parent post. We've used this method on production sites for years without issues.

Plugins aren't the enemy—quality ones like Yoast enhance security and performance. Read our guide on optimal plugin counts for best practices. We stick with Yoast and simply toggle this checkbox.

On our sites, we keep attachments accessible but exclude them from XML sitemaps and add noindex, nofollow via Yoast's Titles & Metas » Post Types for attachments only. This prevents indexing without full disablement.

This approach has streamlined our sites and boosted user satisfaction. Questions? Drop a comment below—we're here to help.