How to Disable Image Attachment Pages in WordPress

For this article, we’ve decided to tackle the disable attachment pages in your WordPress website issue, what it is and reveal all the best solutions to resolve the issue.

How to disable image attachment pages

By default, whenever you upload an image to your WordPress website, WordPress will create a URL for that file. This way you will be left with image attachment pages that users can click on the link from Google and all they’ll be displayed in a single image. 

This will have your website look incomplete or unprofessional, leaving them in total confusion as to what happened to the rest of the website. If you are running a blog on WordPress or selling from your online store, leaving such pages behind can have a negative impact on the bounce rate of your website. 

For this article, we decided to shed a light on what this WordPress issue is and how to disable image attachment pages in WordPress with a few simple methods. Read on to learn more. 

What are image attachment pages and how to disable them in WordPress?

As noted before WordPress by default will create URL pages for every media attachment you upload on your WordPress website, these include images, videos/audio files, pdf,  documents and other attachment files.

And this is an issue that not most WordPress users are aware of. In such cases, a user can easily access the image attachment pages created on your website and all they will see is the image and blank content, besides the sidebars and footer. 

It is of no importance and useless to leave such pages that link to your attachment files with no other content on them. If you have a photography website build on WordPress, of course, you would want users to thoroughly examine your images, but these image attachment pages are of no value and can hurt your SEO. And if you wish to show your image in more detail then a lightbox feature is what you need in this case. 

Now that we have the basics clear, let’s get to work and see how you can disable image attachment pages in WordPress. The methods covered are simple yet effective toward this issue. 

Disable Image Attachment Pages in WordPress using a plugin

In this article, we will lay down all the methods and approaches that you can take in order to disable the image attachment pages in WordPress. The methods covered in this article will present a simple and effective approach by using WordPress plugins for the job or b inserting code in the theme files of your website. 

You can use one or the other, whichever fits you and your website. If you are a novice in the WordPress world, then using a plugin will probably be the easy way out as it will offer you a simple and automated process. But if you are more tech-savvy and don’t want to overburden your WordPress website with more plugins, the second approach will be best suited. 

Rank Math Plugin

Rank Math is an amazing SEO WordPress plugin that aims to help you all te way to the top of search engine pages with multiple advanced tools and options available. You can install the plugin for free from the WordPress repository. 

You install it just like any other WordPress plugin, from WordPress > Plugins > Add New. Search for the Rank Math plugin and click on Install. After installation, activate the plugin and you’re good to go. 

Once you’ve set up the Rank Math plugin, from the WordPress Dashboard > Rank Math > General Settings. There you will have a list of settings to configure, the first tab contains the configurations of links. Switch the handle ON for Redirect Attachments.  

How to disable image attachment pages in WordPress

This setting will have your attachment URL pages to their parent URL, meaning to the post they appeared. This option is switched on by default in Ran Math. and below the Redirect Attachment settings, you have also Redirect Orphan Attachment. This configuration will allow the attachment URL to redirect to your homepage if there can not be a parent URL for the attachment.

Attachment Pages Redirect Plugin

Another alternative plugin to disable image attachment pages in WordPress is the Attachment Pages Redirect plugin that’s designed specifically for the job. If you don’t want to use an SEO plugin, the Attachment Pages Redirect plugin is the right choice for you. And the entire process is really intuitive and automated. 

All you have to do is install the plugin, activate it and it will automatically redirect users to the parent URL when they click upon an image attachment page in WordPress.  

The plugin will automatically redirect users to the parent page without you having to configure settings, you can keep doing your work like usual while the plugin runs on the background. And when there is no parent page to be found the plugin will automatically redirect users to your homepage once they land on an image attachment page. 

Yoast SEO

Here’s another all-in-one SEO plugin that offers the most advanced settings and configurations to upgrade your SEO plan and strategy. Yoast SEO plugin is the perfect choice to disable image attachment pages in WordPress as well as lay the foundation of your SEO strategy to rank higher on search engines. 

The plugin offers a simple and highly intuitive interface that will make even the most novice user comfortable with its skillset. It is as simple as installing the plugin from the WordPress repository. Search for the plugin, install it, and activate it to start the process. 

After you’ve installed the plugin, it will appear on the left panel of the WordPress Dashboard. Click on Yoast SEO > Search Appearance. Then move on to the Media Tab. From there you will need to switch the Media & Attachment URLs option ON. This will have all the image attachment pages and other media attachments be redirected to the parent URL itself. Click on Save Changes for them to take place and you’ll be good to go. 

How to disable image attachment pages in WordPress

Disable Image Attachment Pages in WordPress via Code Snippet

Now we move onto the advanced stuff, if you don’t want to add another plugin to burden your WordPress website, then you can disable image attachment pages by inserting a code line in the image.php file from your website.  

In order to access the image.php file of your website, you can easily do that via the FTP client or by using the File Manager tool from cPanel, either way, it’s correct. For this article, we went with the second option. We will access the File Manager setting from cPanel. 

how to access the htaccess file via cPanel File Manager

We advise you use the child theme when making any changes to the core of your theme in case something goes wrong, eliminate the risk of the code snippet being removed when future updates are due for the theme. 

From File Manager, access the wp-content file in the root directory. Once you’ve done that click on the themes folder. From there you can access your theme’s folder, it is usually named based on the name of the theme. Search for the folder and click on it. Next would be to locate the image.php file and edit it and add the following code snippet at the top of the file. 

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


In case you don’t find the image.php file, then you will need to create in the theme’s folder and name it image.php, and as mentioned paste the code granted below. Save the changes you’ve made and you’ll be done. WordPress will redirect image attachment pages to their parent URL pages. 

Final Thoughts

This concludes our article on how to disable image attachment pages in WordPress. We thoroughly described how to fix the image attachment pages issue in three easy methods. WordPress repository offer a broad scope of functionality to your WordPress websites, and disabling image attachment pages is no exception.

As we mentioned, WordPress by default creates URL pages for every media attachment you upload on your website whether that be images, videos, files, documents, pdfs, or other attachments. 

This will have your website filled with useless and blank URL pages, and users can easily access these pages and all they are going to see is a blank page with only the attachment you uploaded.

To fix this you could either opt for a plugin to do the job, or you could add a code snippet to your theme’s file and have all your image attachment pages be redirected to their parent URL, the original page they were uploaded. Hope this article helps those in need. 

Leave a Reply

Your email address will not be published. Required fields are marked *