How to Disable Image Attachment Pages in WordPress

By default, WordPress creates a single page for every media attachment you have on your site.

Method 1: Disable Image Attachment Pages in WordPress (with a Plugin)

We recommend using All in One SEO. It’s the best SEO plugin for WordPress used by over 2 million sites. The first thing you’ll need to do is install and activate the plugin. To do this, see our guide on how to install a WordPress plugin. Once the plugin is installed and activated, you’ll have a new menu item called ‘All in One SEO’. Navigate to All in One SEO » Search Appearance. Next, click the ‘Media’ navigation tab.

The first setting is ‘Redirect Attachment URLs’. You can disable the setting entirely, redirect to the attachment page, or the attachment parent page. We recommend redirecting to the ‘Attachment Parent’ page. That way, when a user lands on the image attachment page, they’ll be redirected to your article instead.

Method 2: Disable Image Attachment Pages in WordPress (with Code Snippet)

First, you’ll need to create a new file in your WordPress theme folder and name it image.php. If your theme already has an image.php file, then you’ll need to edit that file instead. After that, all you have to do is add the following code as the first line in your image.php file:

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

Next, you need to save the image.php file and upload it to your theme directory using FTP or your WordPress hosting control panel.