WordPress Disable Image Attachment Page Links – In the following simple solution, I’ll 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, hence 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 Page Links via a Redirect to Parent
- Create a new file named image.php on your desktop
- Open image.php with a text editor, and paste the following into it :
<?php wp_redirect(get_permalink($post->post_parent)); ?>
- Using an FTP client, navigate to your theme folder (wp-content/themes/themename)
- Copy the image.php file from your desktop into your theme folder
Go view an old attachment page on your site. Iif things are working as they should, you should be automatically redirected to the Post that contains that attachment. Source Credit