What's WP
Our everything is about WordPress - best choice of WordPress users!
How to Disable the Image Attachment Pages in WordPress?

How to Disable the Image Attachment Pages in WordPress?

Whenever you attach an image to a new post aiming to spice up the overall contents, you probably never know how this small move will bring some unexpected problems. WordPress creates an independent page for each image that you have uploaded by default, which becomes the crux of the matter.

In this beginners’ guide, we firstly brief the reasons why the matter is generated and how it hurts your website. In the next, we put forward several workable methods to help you disable the image attachment pages in WordPress.

What Are Image Attachment Pages and How They Hurt Your Site?

WordPress, as one of the best CMS applications, provides a plenty of amazing features for users’ sake. However, there remain some flaws with it as well, among which the automatic creation of image attachment pages should be worth mentioning.

To be more specific, when you upload an image to the default directory, WordPress generates a separate page for it. However, unlike any other posts or pages you have added via a visual or text editor, this page contains no virtual contents but the image solely.

What makes things even worse is that these image attachment pages have their permalinks and can be indexed by Google and other popular search engines. It is clear that you will not like these pages appear in this way because they lead to some adverse effects both on the user side and the search engine side.

  • When users visit these pages and find nothing but images, their searching momentum is broken, which in turn leads to a higher bounce rate.
  • With lots of unnecessary pages indexed, your site is likely to get flagged or even banned by Googlebot, which certainly hurts your site visibility.

How to Disable the Image Attachment Pages?

In general, there are two ways to solve the problems caused by image attachment pages – redirecting these pages to their parent posts or blocking them from indexed. Since there are some overlapped operations between the two solutions, we will focus on the former one to help you thoroughly with this process.

Displayed as below, there are three subordinate options to redirect the image attachment pages to their corresponding original posts. The first two options are using plugins that our editors have carefully selected. The last option, on the other side, involves a little bit coding know-how. Feel free to check more detailed descriptions.

Option 1 – Use the setting of Yoast SEO plugin in WordPress

There are more than one million site owners using Yoast SEO, one of the most excellent SEO plugins over the Internet. As a result, if you are a member of them, you can disable image attachment pages with ease using the setting of this wonderful plugin.

Simply navigate to “Advanced” > “SEO” on the sidebar of your dashboard. Then, head over to the “Permalinks” tab. As the following screen capture displays, all you need to do here is click the checkbox next to the “Redirect attachment URL’s to parent post URL” option.

Redirect Attachment URL

Finally, remember to hit the “Save Changes” button to enable this setting and you are done.

Option 2 – Install the Attachment Pages Redirect plugin or similar

The second option in nature acts as a “plan B” of the first one, which revolves around using plugins. Despite not being updated for nearly two years, the Attachment Pages Redirect plugin is indeed a good tool to redirect all image attachment pages to their parent posts.

The details of using this plugin are quite simple. All you need to do is install and activate it in the same process as that of any WordPress plugin installation.

Install the Attachment Pages Redirect Plugin

Then there is no more other setting or configuration. Once the plugin is initialized, it starts redirecting users who land on each of the attachment pages to a new location – the corresponding parent post. Besides, when no parent post is available, it will redirect users to the homepage of your site.

Option 3 – Add an 1-line redirect code to the theme folder or image.php file

The last option is using a simple 1-line redirect code. You can get started by opening a text editor like Notepad++ to create a new .php page. Secondly, paste the following code into it. Then, save it as “image.php” and upload this file to your theme directory.

If you already have a namesake file in your theme, just insert the code as the first line of that file, save changes, and in the final ring the bell.

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

All in all, from the three optional methods above, you can choose one according to your preference or needs to disable image attachment pages by redirecting them to the parent posts.


Susan Rose is a freelance writer who has a deep knowledge about WordPress. She loves everything related to website building since the freshman year at Christopher Newport University, and loves to share her experience with people all over all the world. This girl is popular among our readers as she is outgoing and energetic. In the daily life, Susan loves detective novels as it can train her logical thinking and creativity.


Want to Learn More About WordPress?

Get Our Free Themes, Plugins, Support, SEO Tips, and Other Tutorials!

Email *