{"id":26848,"date":"2021-07-13T15:00:51","date_gmt":"2021-07-13T13:00:51","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=26848"},"modified":"2021-07-13T09:35:35","modified_gmt":"2021-07-13T07:35:35","slug":"how-to-disable-image-attachment-pages-in-wordpress","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/how-to-disable-image-attachment-pages-in-wordpress\/","title":{"rendered":"How to Disable the WordPress Image Attachment Page"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]Even though WordPress is the world\u2019s foremost content management system, it\u2019s still far from being flawless. While its shortcomings aren\u2019t massive enough to put even the slightest dent in its popularity, they are something you will occasionally have to deal with.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]For instance, there are more than a couple of issues that might come up when working with <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-fix-common-image-issues-wordpress\/\">images in WordPress<\/a>. The inability to deal with image attachment pages is a problem that can\u2019t be rectified through an option in core WordPress.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]So how do you prevent people from landing on image attachment pages? You\u2019ll find out in this article. We\u2019ll cover:<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#what-are-image-attachment-pages\">What Are Image Attachment Pages<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#whats-the-problem-with-them\">What\u2019s the Problem With Them<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#how-to-redirect-attachment-urls-using-plugins\">How to Redirect Attachment URLs Using Plugins<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#how-to-redirect-attachment-urls-using-code\">How to Redirect Attachment URLs Using Code<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;80px&#8221;][vc_widget_sidebar sidebar_id=&#8221;new-top-picks-banner&#8221;][vc_empty_space height=&#8221;80px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"what-are-image-attachment-pages\"><\/a>What Are Image Attachment Pages?<\/h2>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;21px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"605\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Image-Attachment-Page.jpg\" class=\"attachment-full size-full\" alt=\"Image Attachment Page\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Image-Attachment-Page.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Image-Attachment-Page-300x187.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Image-Attachment-Page-768x480.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Image-Attachment-Page-620x387.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>Whenever you upload a media file through the media library, WordPress will create an attachment page for it.<\/strong> These attachment pages contain information about the file you uploaded, like a description or the name of the file. <strong>They also have permalinks.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]An image attachment page is an attachment page that gets created whenever you upload an image through the media library. The information it contains is not limited to the name and description \u2013<strong> it can also contain data such as the resolution of the image, as well as the EXIF data.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"whats-the-problem-with-them\"><\/a>What\u2019s the Problem With Them?<\/h2>\n<p>[\/vc_column_text][vc_column_text]There are a couple of reasons why image attachment pages might cause problems. <strong>For one, they can be reached by audiences who just wanted to see your image files, and they might not be impressed by the presentation they see.<\/strong> In an ecosystem where quick impressions matter a lot, this can have a detrimental effect.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The image attachment page\u2019s usefulness for search engine optimization is also questionable.<strong> While it\u2019s stated on WordPress.org that using attachment templates might help SEO, there seems to be little agreement to it.<\/strong> Yoast SEO, for example, advises against letting visitors reach attachment pages.<strong> It\u2019s also a fact that search engines like quality content, which these pages simply aren\u2019t.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Finally, the problem is that you can\u2019t just up and delete them. <strong>The way to handle them usually includes making them harder to reach, not removing them altogether.<\/strong> So now that we know that you can\u2019t exactly make them disappear or stop appearing, let\u2019s see what options you have to redirect around them.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"how-to-redirect-attachment-urls-using-plugins\"><\/a>How to Redirect Attachment URLs Using Plugins<\/h2>\n<p>[\/vc_column_text][vc_column_text]We\u2019re talking about WordPress here, so there\u2019s bound to be a plugin that can help you deal with those image attachment pages, right?<strong> There are a couple of them, and some of them are popular enough that you might already have them.<\/strong> Keeping to a reasonable number of plugins is always a good idea, too.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>If you use Yoast SEO, you\u2019re able to redirect attachment URLs directly to the media files they were created for.<\/strong> With Yoast SEO installed, navigate to <em><strong>SEO &gt; Search Appearance &gt; Media<\/strong><\/em>. You\u2019ll notice the Media &amp; Attachment URLs option and a toggle to enable redirecting.<strong> It will be set to \u201cYes\u201d by default.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"422\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Search-Appearance-Yoast.jpg\" class=\"attachment-full size-full\" alt=\"Search Appearance Yoast\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Search-Appearance-Yoast.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Search-Appearance-Yoast-300x131.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Search-Appearance-Yoast-768x334.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Search-Appearance-Yoast-620x270.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]If you don\u2019t want to redirect to media files, you can try downloading the <a href=\"https:\/\/wordpress.org\/plugins\/attachment-pages-redirect\/\" target=\"_blank\" rel=\"noopener\">Attachment Pages Redirect<\/a> plugin. The plugin is available from the WordPress.org repository, and it doesn\u2019t have any settings. <strong>You just need to install and activate it and it will start working.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Attachmet-Pages-Redirect.jpg\" class=\"attachment-full size-full\" alt=\"Attachmet Pages Redirect\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Attachmet-Pages-Redirect.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Attachmet-Pages-Redirect-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Attachmet-Pages-Redirect-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/07\/Attachmet-Pages-Redirect-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>With Attachment Pages redirect, the image attachment pages will redirect to their parent post \u2013 the post they were uploaded through.<\/strong> If you uploaded the image directly to the image library using the<em><strong> Media &gt; Add New<\/strong><\/em> option, the link will be redirected to the website\u2019s home page. The choices of the page the users will see also depend on whether or not the parent page exists anymore.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"how-to-redirect-attachment-urls-using-code\"><\/a>How to Redirect Attachment URLs Using Code<\/h2>\n<p>[\/vc_column_text][vc_column_text]If you\u2019re comfortable with writing some code \u2013 copying it, really \u2013 then you don\u2019t have to rely on plugins at all. <strong>You should be sure that you have no problem with handling code because you will need to change your theme\u2019s files or add a file to your WordPress installation.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The code we\u2019ll be using goes like this:<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?php \r\nglobal $post;\r\nif ( $post &amp;&amp; $post-&gt;post_parent ) {\r\nwp_redirect(esc_url(get_permalink($post-&gt;post_parent)), 301);\r\nexit;\r\n} else {\r\nwp_redirect(esc_url(home_url( '\/' )), 301);\r\nexit;\r\n}\r\n?&gt;<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>This code will redirect visitors to the parent post if it\u2019s available. Otherwise, it will take the visitors to your website\u2019s homepage.<\/strong> For it to work, you have to paste it on the top of the file that contains your attachment page template, which might be the attachment.php file. However, if there is an image.php file in your theme, you might want to add the code there.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]If your theme doesn\u2019t have an attachment.php or an image.php file, you\u2019ll want to create one of them. <strong>All the more reason to simply use a plugin if you\u2019re not sure how to create these files and add them to your WordPress installation.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Let\u2019s Wrap It Up!<\/h2>\n<p>[\/vc_column_text][vc_column_text]Even though image attachment pages aren\u2019t a big issue that could cause some serious damage to your website, they can lead to some confusion \u2013 both the visitors and the search engines. That might be the reason why it\u2019s often recommended you deal with them. Usually, the way to do it is to ensure that even the people who have the link to these pages end up somewhere else.<br \/>\n[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Want to make those image attachment pages disappear? We&#8217;ll show the next best thing &#8211; how to set up redirects so that no website visitor can find them.<\/p>\n","protected":false},"author":9295,"featured_media":26866,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[27,4,13],"class_list":["post-26848","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-content","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/26848","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/9295"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=26848"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/26848\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/26866"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=26848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=26848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=26848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}