Image attachment pages give an impression of incomplete pages on your site. A visitor can have a poor impression of your site after visiting attachment pages that look like incomplete pages and show up to visitors. This article details the procedure to disable image attachment pages in WordPress and redirect to the parent page.
Why Disable Image Attachment Pages?
WordPress creates a single page for every media attachment you have on your site.
Images, audio and video files, and PDFs are all included in this category. While some WordPress users might find this helpful feature, it isn’t required for most websites.
The attachment page could display EXIF data, for example, in a photography theme. The camera model, the camera settings, and even the image’s location data could be displayed.
Users frequently complain about the appearance of their images after they have unintentionally linked them to the attachment pages.
Because many themes don’t have unique templates for the image attachment pages, this is a significant problem for the site.
Popular images on your website may cause visitors to arrive at your attachment page directly from Google search results.
Ideally, you want your readers to see the image in the context you have used it when they arrive at your post.
As a result, we always advise our WordPress users to turn off the image attachment pages on their site.
Disable Using Code Snippet
WordPress code snippets can also be used to accomplish the same thing as a plugin.
Instead of relying on an external plugin, you can use this method to get the job done without one.
To begin, create a new file called image.php in your WordPress theme folder. If an image.php file already exists in your theme, you’ll need to make the necessary changes to that file instead.
Adding the following code to the top of your image.php file completes the process.
<?php wp_redirect(get_permalink($post->post_parent)); ?>
Image.php is saved and uploaded to your theme directory via FTP or WordPress’s control panel.
When someone visits your image attachment page, they will be redirected to the original article.
Disable With Plugin
WordPress plugins make it incredibly simple to turn off the display of image attachment pages. This approach is simple enough for even non-programmers to use.
Many plugins are available in the WordPress repository, which can be used to disable image attachment pages. Check out SEOPress and All in One SEO.
‘Redirect Attachment URLs’ is the option. You have the option of completely disabling the setting, redirecting to the attachment page, or redirecting to the attachment parent page.
Redirecting to the ‘Attachment Parent’ page is recommended. Users will be redirected to your article instead of the image attachment page if they visit the image attachment page.
To disable image attachment pages in WordPress, we hope this article was helpful. Check out our beginner’s guide to image SEO and our guide to fixing typical image issues in WordPress for additional information.
You can find more of our WordPress tutorials on our YouTube Channel, so please check it out if you enjoyed this one. Twitter and Facebook are also great places to find us.