Disable Image Attachment Pages in WordPress

WordPress Disable Image Attachment Pages. In the following simple solution, I show you one way to remove or prevent attachment pages from appearing for every image attachment you add to WordPress. Because WordPress stores attached image data in the database as a Post Type, a URL is automatically created for each image.

As a work-around, one can simply redirect the attachment URL to the parent post of the attached image.

Disable Image Attachment Pages in WordPress | Redirect to Parent

  1. Create a new file named image.php on your desktop
  2. Open image.php with a text editor, and paste the following into it :
    <?php wp_redirect(get_permalink($post->post_parent)); ?>
  3. Using an FTP client, navigate to your theme folder:
    wp-content/themes/theme-name/
  4. Copy the image.php file from the desktop into your theme's folder.

Go view an old attachment page on your site. If things are working as they should, you should be automatically redirected to the post that contains that image or attachment, instead of a separate attachment landing page. Source Credit