Do you want to disable image attachment pages in WordPress?
Image attachment pages often look incomplete, and if a visitor views these, then it can leave a poor impression. Many visitors will simply leave rather than try to find the attachment itself or its parent post.
In this article, we’ll show you how to disable image attachment pages in WordPress and redirect 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 photography theme could use the attachment page to display EXIF data. This could show the camera model used, the camera settings, and even the image’s location data.
Many WordPress blog owners will accidentally link their images to the attachment pages instead of the image itself, or they don’t like the way it looks because many themes don’t have special templates for the image attachment pages.
Sometimes an image on your website can become popular, and people might start landing on the attachment page directly from Google. Ideally, you want visitors to land on your post and see the image in the context you have used it.
To help solve this problem, we’ll show you two different ways to disable image attachment pages in WordPress, so you can choose the best one for you.
Method 1: Disable Image Attachment Pages in WordPress (with a Plugin)
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.
If the media does not have a parent post, AIOSEO will redirect visitors to the site’s homepage.
Once you select your preferred setting, make sure to click ‘Save Changes’ before exiting the screen.
Method 2: Disable Image Attachment Pages in WordPress (with Code Snippet)
Upon activation, you will want to find Code Snippets » Add Snippet in your admin dashboard.
Then, simply type ‘attachment’ into the search field. A snippet titled ‘Disable Attachment Pages’ should appear on the right.
When you hover over it, click the ‘Use Snippet’ button. You will be taken to the ‘Edit Snippet’ page where all of the settings are set for you automatically.
All you need to do is toggle the switch to ‘Active’ and click the ‘Update’ button.
Now, when a user lands on your image attachment page, they’ll be redirected to the parent post. If there is no parent post for the image, then the user will be redirected to the site’s homepage.