How to Disable Image Attachment Pages in WordPress

WordPress by default creates a single page for each attachment that you have on your site. This includes images, audio/video files, pdfs, etc. This functionality is great for photographers, but not so much for the rest of us. Often we get complaints from beginners who accidentally linked their images to the attachment pages, and they don’t like the way it looks. That’s a big issue because a lot of themes don’t have special templates for the image attachment pages. Sometimes an image on your website can become popular and people might start landing on the attachment page directly from Google. Ideally you would want them to land on your post and see the image in the context you have used it. In this article, we will show you how to disable image attachment pages in WordPress.

If you are already using WordPress SEO by Yoast plugin, then go to your SEO » Permalinks options page. All you have to do is check the box next to “Redirect attachment URL’s to parent post URL”. This will redirect users arriving at attachment pages to the parent post.

For those who are not using the WordPress SEO by Yoast plugin, you can still disable image attachment pages and redirect users to parent post using another plugin called Attachment Pages Redirect. All you have to do is install and activate the plugin. Upon activation the plugin starts redirecting users landing on attachment pages to parent post. If no parent post is found, then the users are redirected to homepage. This plugin works out of the box and has no settings page. Simple and easy.

If you are among those who don’t like plugins, then there is an option for you as well that. Create a new file in your WordPress theme folder and name it image.php. If your theme already has an image.php file, then you need to edit that instead. All you have to do is add this code as the first line in your image.php file :

Tables can't be imported directly. Please insert an image of your table which can be found here.

1

Save image.php file and upload it into your theme directory. Now when a users reaches the image attachment page, then they will be redirected to the parent post.

Was this article helpful?
0 out of 0 found this helpful