How to disable image attachment pages in WordPress

Would you like to disable image attachment pages in WordPress?

Image attachment pages can look like incomplete pages on your website. When a visitor sees these, it can make a bad impression.

In this article, we’re going to show you how to disable image attachment pages in WordPress and forward them to the parent post.

Why should you disable image attachment pages in WordPress?

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

This includes images, audio / video files, PDFs, and more. Some users might find this functionality useful, but most WordPress websites don’t need it.

For example, a photo theme could use the attachment page to display EXIF ​​data. This can show the camera model in use, the camera settings, and even the location data of the image.

Often times we get complaints from users who mistakenly linked their images to the attachment pages and they don’t like the look.

This is a big problem as many themes don’t have specific templates for the image attachment pages.

Sometimes an image can become popular on your website and users may land on the attachment page straight from Google.

Ideally, you want visitors to land on your post and see the image in the context in which you used it.

For this reason, we always recommend users to disable image attachment pages on their WordPress blog.

How To Disable Image Attachment Pages In WordPress (2 Methods)

There are two ways to disable image attachment pages in WordPress.

The first approach uses WordPress plugins while the second involves adding custom code to WordPress.

You should choose the method that works best for your skills.

Method 1: disable image attachment pages in WordPress (using a plugin)

The easiest way to disable image attachment pages is to use a WordPress plugin. This method is beginner-friendly and doesn’t require any coding.

We recommend using All in One SEO. It’s the best SEO plugin for WordPress that is used by over 2 million websites.

The first thing to do is to install and activate the plugin. You can find information on this in our instructions for installing a WordPress plugin.

As soon as the plugin is installed and activated, you have a new menu item called “All in One SEO”.

Navigate to All in One SEO »Search Appearance. Then click the “Media” navigation tab.

All-in-one media setting for SEO search look and feel

The first setting is “Redirect Attachment URLs”. You can deactivate the setting completely, redirect it to the attachment page or to the parent attachment page.

We recommend redirecting to the “Parent Attachment” page. That way, a user who lands on the image attachment page will be redirected to your article instead.

All in One SEO choose attachment parent

When you have selected your preferred setting, click “Save Changes” before exiting the screen.

If you’re not using the all-in-one SEO plugin, you can still disable image attachment pages and redirect users to a parent post using the Attachment Page Redirection plugin.

All you have to do is install and activate the plugin. Users who land on attachment pages are automatically redirected to the parent post.

If no parent post is found, users will be redirected to your homepage.

This plugin works out of the box and has no settings page. Simple and easy.

Method 2: disable image attachment pages in WordPress (using code snippet)

Another option is to add a snippet of code to WordPress, which accomplishes the same goal as the plugin above.

If you don’t want to use a plugin or if you feel like you are already using too many WordPress plugins, you can use this method.

First, you 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, you’ll need to edit that file instead.

After that, all you need to do is add the following code as the first line of your image.php file:

post_parent)); ?>

Next, you’ll need to save the image.php file and upload it to your themes directory via FTP or your WordPress hosting control panel.

When a user lands on your image attachment page, they’ll be redirected to the parent post.

We hope this article has helped you to disable image attachment pages in WordPress. You may also want to check out our Beginner’s Guide to Image SEO and our Guide to Fixing Common Image Problems in WordPress.

If you enjoyed this article, please subscribe to our YouTube channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Comments are closed.