How to Disable Image Attachment Pages in WordPress

This article is about disable image attachment pages in WordPress and how to get rid of them.

Some of you may not know that every time you upload a media file such as an image or video, WordPress automatically creates a dedicated page for the media file. That is exactly why when you click on an image, it opens up as a webpage. It is literally a waste of space to have a single page of each attachment. The same is true for audio file as well as PDF, doc and such attachment files.

When a user clicks on such attachment a separate page opens, it looks quite ugly because most of the themes do not have a template for such a situation. It might so happen that a particular image or video become popular and in such a scenario, users will be landing on the separate page for the file rather than the post. Therefore, it is highly important to disable image attachment pages in WordPress no matter what.

But the problem of image attachment pages is far greater. You can protect your posts and pages through encryption and prevent cyberattacks. But these image attachment pages are something people are unaware of, and these are the pages hackers target to get a backdoor. These media attachment pages contain important information that you would not like to reveal in public. There are two ways to deal with the problem. You can either redirect or disable image attachment pages in WordPress.

When and How To Disable Image Attachment Pages in WordPress –
Suppose you have tutorials of your website which you give access to users who pay for them. Some of these tutorial pages must have informative images and infographics. If image attachment pages are accessible, people will steal your copyright images and take undue advantages by sharing them on social media. In such scenario, you need to hide the pages and make sure they are only available only to the granted users.

To hide them, you have to connect your FTP software to your web server and locate the file image.php and add a line of code in it. If the file is not present, you can create it and write the code and upload it to the root directory.

The next time someone attempts to access your image, he will be redirected to the homepage. Similarly, you can add the same protection for your videos by creating or editing video.php. But if you are afraid of codes and uploading file on the web server, you can always use a plugin to get the job done.

Using A Plugin To Hide Image Attachment Pages in WordPress –
The popular plugin Attachment Pages Redirect is your destination. It redirects all the available images and videos as well media file attachment pages to the home page or parent page or any custom page you would like to redirect. The plugin has good reputation and rating.

Go to Admin Dashboard and from the left menu, go to Plugins> Add New. Search the plugin by its name and install and activate it. After that, you can go to Settings and select the page where a user will be redirected.

Second Plugin
Most of the users have WordPress SEO By Yoast plugin installed. In case, you do not have it, go ahead and install it. Apart from protection, you will avail yourself a lot of features with just one plugin.

Once installed and activated, go to SEO option from the left menu of the Dashboard and click on Permalinks option from the drop down. You will see the option “Redirect Attachment URL’s to parent post URL”. So, the next time some tries to access the media attachment pages intentionally or accidentally, they will be redirected to the homepage.

You will come across several such plugins, but it is recommended to use code because a third-party plugin always consumes more resources and slows down execution and loading speed. You can appoint a web developer to do all the custom programming at once to fix all the issue, and in that way, it will cost you less rather than appointing him over and over again for every problem and issue you come across.
What Are The Other Steps You Can Take?

There could be instances when you need image attachment pages but when you share the link and if users open it, they will get redirected. Instead, you can keep the attachment pages natural without redirection and exclude those pages from your sitemap. In that way, search engines will not index those pages, and they will not come up in image search or web search page link.

Furthermore, you can add meta robots text nofollow, noindex to every attachment pages using Yoast SEO plugin so that no one can link to those pages and get undue benefits in SEO. You will find the option on Titles & Metas tab and under Post Types. Enable Noindex and Nofollow tags only for attachment post types.

It is important for you to understand that no process is foolproof. Hackers always find a way out but you have to do whatever you can to protect yourself rather than being hopeless. For example, if someone wants to get access to your copyright images, he can get access to your post and take a screenshot.

Furthermore, inspecting the source code on the web browser will unveil the attachment URL that they can use to get direct access without redirection. There are certain complicated steps to prevent such steps as well like disabling screenshot feature or right-click feature on your website and doing server-level redirection to prevent direct URL access. But it would only make your website script-heavy, and the loading speed will go up significantly.

It is important to understand that you cannot fully protect anything in this world. But with basic and necessary steps you can easily stop the amateur ones who are likely to steal your stuff and devalue the item in the market. Hope you have understood how to hide or disable image attachment pages in WordPress.

About Shri Posts

Shri shares exciting WordPress themes, plugins and other WordPress related news for our viewers. He also posts selected WordPress developers interviews from time to time.

SKT Free Software Theme