Hosting Tutorial & Guide

How to Disable WordPress Attachment Pages from Visitors

updated on May 31, 2017
How to Disable WordPress Attachment Pages from Visitors WordPress which has served many personal blogs and websites can be regarded to be the most powerful content management system. However, it does not mean that there is no drawback in WordPress, for example, WordPress attachment pages.

The items you have uploaded to your WordPress site, such as images, PDFs and audios, will automatically create attachment pages. For these pages, search engines may display them in the search results, so when visitors search for the original post, they may click into the attachment pages instead of the real post they want. In such cases, the attachment pages have a negative impact on the SEO performance of WordPress sites. This article exactly shows you how to disable WordPress attachment pages from visitors.

How to Disable WordPress Attachment Pages from Visitors

In fact, attachment pages can be indexed under the unique URLs. To avoid troubles, it is necessary for you to prevent search engines from indexing your WordPress attachment pages. The best way is to redirect the attachment URLs to the post they were attached to, which tells search engines that the attachment pages have been moved. This can be done with the help of plugins.

The Yoast SEO Plugin

There is a premium plugin - Yoast SEO - which can be downloaded in the WordPress Plugin Directory. With more than 1 million installs, Yoast SEO is useful for you who want to disable WordPress attachment pages. To begin with, you need to land on the Plugins > Add New page where you can quickly find the plugin with the search bar.

Yoast SEO

Upon activation, you may have noticed that the SEO tab has been added to your Dashboard. At this moment, you need to click SEO > Advanced and then go to the Permalinks page so as to enable "Redirect the attachment URLs to parent post URL". Having finished the configuration, you should not forget to save your changes.


The Attachment Pages Redirect Plugin

You can also rely on Attachment Pages Redirect if you try to find another useful plugin. Attachment Pages Redirect distinguishes from Yoast SEO due to the ease of use because it does not require you to make any changes. Once set up, the Attachment Pages Redirect plugin will automatically disable WordPress attachment pages and then redirect the attachment URLs to either the post parent or the homepage.

The image.php File

There are some instances where you are bothered to add plugins. If so, you can completely disable WordPress attachment pages from visitors with the customization of image.php file. If there is no image.php file in child theme, you need to create a new one, enter the below code into it, and then save the changes.

image.php File

At present, the image.php file will make attachment pages redirected to post parent where the media files were uploaded. If WordPress attachment pages were uploaded directly in the media library, they will be redirected to the homepage.

Final Verdict

Since WordPress attachment pages often come with few content, you need to disable them for the better improvement of WordPress SEO via the Yoast SEO plugin, the Attachment Pages Redirect plugin, or the image.php file. In our experience, we recommend the Yoast SEO plugin most.