Awesome WordPress Themes At Great Prices Get 15% Off Use Code "Ovation15"

Disable Image Attachment Pages in WordPress: Are you facing trouble issues with the Image attachment pages on your website? If yes, then we have got perfect ways to disable them from your website.

Image attachment pages are automatically generated pages when any media is uploaded in WordPress. These pages contain no content but occupy unnecessary space on your website. While this creates a bad impact on SEO, as crawlers can be directed to image attachment pages instead of the main content.

To stop this, you must disable image attachment pages from your website. And therefore, we have got two ultimate solutions to help you disable image attachment pages in WordPress.

Disable Image Attachment Pages in WordPress

Ways to Disable Image Attachment Pages in WordPress

Method 1: Disable Image Attachment Pages in WordPress using a plugin.

Method 2: Or you can try using a code snippet.

Method 1: Disable Image Attachment Pages in WordPress using a Plugin

  • This is the first method we are going to apply to disable image attachment pages in WordPress. We are heading with one of the most popular SEO plugins All-in-one SEO.
  • The first that should be done is to install and activate the All-in-One SEO plugin. Once done activating, you will now see that the plugin is added under the menus.
  • Now, take your mouse pointer to the All-in-one-SEO and then tap the Search Appearance option.
  • You will see various menus on the header panel. Of these, you need to select the Media menu and it will switch to the new window.
  • You will find the first option “Redirect Attachment URLs”. Here you get three options to select either from Disabled, Attachment, and Attachment Parent.
  • Here, we are going with the third option which is the Attachment Parent page. This way whenever a user visits the image attachment page, it will take it to the article instead.
  • And in case of no parent posts, it will redirect to the homepage.
  • And lastly, you need to press the Save Changes button.

Method 2: Disable Image Attachment Pages in WordPress with a code snippet.

  • Here comes the next method to disable image attachment pages using a code snippet.
  • And for this method, we will be using the plugin WPCode plugin. So to start with, we need to install and get this plugin activated on the website.
  • Straightway reach the Plugins section under the WordPress dashboard and tap the Add New button.
  • Next, search for the WPCode plugin in the search bar.
  • Simply tap the install button and once done, press the activate button.
  • Again visit the admin dashboard and find the WPCode plugin.
  • Tap the WPCode plugin option and then tap the Add Snippet option.
  • You will reach the next page where you need to search for “Attachment”.
  • Here, you will find a snippet named “Disable Attachment Pages”. Once you click on it, a button named “Use Snippet” will activate, simply press the button.
  • You will reach the page where everything is done by default for you including the code below:



function () {

global $post;

if ( ! is_attachment() || ! isset( $post->post_parent ) || ! is_numeric( $post->post_parent ) ) {



// Does the attachment have a parent post?

// If the post is trashed, fallback to redirect to the homepage.

if ( 0 !== $post->post_parent && ‘trash’ !== get_post_status( $post->post_parent ) ) {

  • You simply need to do after this to enable the “Inactive” button to “Active”. Lastly, press the Update button to save the changes.
  • From now on, whenever a user visits the image attachment pages, it will reach the parent article. And if no parent page is there, it will simply be dropped to the homepage.


This is how you can easily disable image attachment pages in WordPress. I hope this article has thoroughly helped you with this easy process. As image attachment pages can be a wall between your website and the SEO ranks. So better way, you must remove them from your website using one of the above methods. These methods can be used in all WordPress themes.

Related Post

Leave a Comment

The reCAPTCHA verification period has expired. Please reload the page.

Translate »