{"id":12620,"date":"2021-05-21T10:30:03","date_gmt":"2021-05-21T07:30:03","guid":{"rendered":"https:\/\/vipestudio.com\/?p=12620"},"modified":"2021-06-11T11:07:51","modified_gmt":"2021-06-11T08:07:51","slug":"a-guide-to-disabling-media-attachment-pages-on-wordpress","status":"publish","type":"post","link":"https:\/\/vipestudio.com\/en\/a-guide-to-disabling-media-attachment-pages-on-wordpress\/","title":{"rendered":"A Guide to Disabling Media Attachment Pages on WordPress"},"content":{"rendered":"<p style=\"text-align: left;\">As any WordPress agency for development worth their late-night coffee will tell you, media attachment pages <strong>do not leave a good impression<\/strong> on visitors to your website, as they can look unprofessional and incomplete.<\/p>\n<p style=\"text-align: left;\">Today we\u2019ll look at two ways to disable these pages, instead of redirecting to the original post on WordPress.<\/p>\n<h2 style=\"text-align: left;\">Why Do We Even Need to Disable Attachment Pages<\/h2>\n<p style=\"text-align: left;\">For all sorts of media, including images or even documents, WordPress creates a page on your site \u2013 a media attachment page. While there are certain use cases where this feature might be useful, most websites <strong>don&#8217;t need a separate page<\/strong> for every single attachment that has been uploaded.<\/p>\n<p style=\"text-align: left;\">Most themes for WordPress don&#8217;t even have a template for these pages, and they end up looking inconsistent with the rest of the website. Getting the <a href=\"https:\/\/vipestudio.com\/en\/wordpress-website-development\/\">help of a WordPress agency for development<\/a> could help with clearing up such inconsistencies, but even then, an attachment page isn\u2019t really necessary for most kinds of websites.<\/p>\n<p style=\"text-align: left;\">Another reason to disable these pages is that an image on your website might get a lot of hits from search engines, but instead of landing on the content where the image is displayed, visitors from Google (or any search engine) might end up on its media attachment page.<\/p>\n<h2 style=\"text-align: left;\">Disabling Attachment Pages<\/h2>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"wp-image-12621 aligncenter\" src=\"https:\/\/vipestudio.com\/wp-content\/uploads\/2021\/05\/Pasted-into-A-Guide-to-Disabling-Media-Attachment-Pages-on-WordPress.png\" width=\"457\" height=\"451\" srcset=\"https:\/\/vipestudio.com\/wp-content\/uploads\/2021\/05\/Pasted-into-A-Guide-to-Disabling-Media-Attachment-Pages-on-WordPress.png 714w, https:\/\/vipestudio.com\/wp-content\/uploads\/2021\/05\/Pasted-into-A-Guide-to-Disabling-Media-Attachment-Pages-on-WordPress-300x296.png 300w, https:\/\/vipestudio.com\/wp-content\/uploads\/2021\/05\/Pasted-into-A-Guide-to-Disabling-Media-Attachment-Pages-on-WordPress-416x410.png 416w, https:\/\/vipestudio.com\/wp-content\/uploads\/2021\/05\/Pasted-into-A-Guide-to-Disabling-Media-Attachment-Pages-on-WordPress-386x381.png 386w, https:\/\/vipestudio.com\/wp-content\/uploads\/2021\/05\/Pasted-into-A-Guide-to-Disabling-Media-Attachment-Pages-on-WordPress-176x174.png 176w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/p>\n<p style=\"text-align: left;\">We\u2019ll discuss two methods to do this. The first approach involves plugins, while the second has to do with custom code that you can add-in. Read through and pick whichever method you\u2019re comfortable with.<\/p>\n<h3 style=\"text-align: left;\">Using a Plugin (or Two)<\/h3>\n<p style=\"text-align: left;\">This is the simpler method, great for beginners, and involves <strong>no code at all<\/strong>. <a href=\"https:\/\/aioseo.com\/?gclid=CjwKCAjwy42FBhB2EiwAJY0yQquMucQncj3b6njd-CS1UfBocQBcFoOSo7JhdCQBSMIAmHLJmuds7hoC_DIQAvD_BwE\" target=\"_blank\" rel=\"nofollow noopener\">All in One SEO<\/a> is a popular plugin that you can use to disable attachment pages as well. Install and activate the plugin, and this will generate a new item in the menu called \u2018All in One SEO\u2019. Click on it and select \u2018Search Appearance\u2019, then go to the \u2018Media\u2019 tab. First, you&#8217;ll see \u2018Redirect Attachment URLs\u2019. Here, you can choose to disable the page, or redirect, either to the attachment page itself or to the parent content URL. We\u2019d advise picking the \u2018Attachment Parent\u2019 option. Once you\u2019re done selecting, \u2018Save Changes\u2019.<\/p>\n<p style=\"text-align: left;\">Another plugin that will do the same thing for you is called \u2018<a href=\"https:\/\/wordpress.org\/plugins\/attachment-pages-redirect\/\" target=\"_blank\" rel=\"nofollow noopener\">Attachment Pages Redirect<\/a>\u2019. Once activated, it will begin redirecting users to the parent page of any attachment. If there is no parent page for the attachment in question, it will send users back to your homepage. There are no settings to change and it just works!<\/p>\n<h3 style=\"text-align: left;\">Using Custom Code<\/h3>\n<p style=\"text-align: left;\">A code snippet can also be used to achieve the same result as the two plugins we have discussed above. If you&#8217;re not comfortable with plugins or you have too many plugins already installed on your website, this might be the method for you.<\/p>\n<p style=\"text-align: left;\">To start, a new file named image.php needs to be created and saved in your WordPress theme folder. If there is already a file in the folder by that name, you can just edit that file. Regardless, on the first line of that file, insert this custom code: <strong>\u00a0wp_redirect(get_permalink($post-post_parent));<\/strong><\/p>\n<p style=\"text-align: left;\">Save the file and upload it to your theme directory via FTP or using the control panel of your WordPress hosting provider. This little snippet of code ensures that the next time a visitor stumbles into one of your attachment pages, they will be promptly redirected to the parent content of the media.<\/p>\n<p style=\"text-align: left;\">With that, we wrap up this article on how to disable media attachment pages on your WordPress website, and we hope you\u2019ve found it useful. We\u2019ll meet you next time with more tips and tutorials on WordPress, and until then, keep dodging those attachment pages!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As any WordPress agency for development worth their late-night coffee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12623,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[113],"tags":[826,829,825,828,827,133],"class_list":["post-12620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website-wordpress-development","tag-attachment-page","tag-custom-code","tag-disable","tag-guide","tag-media-attachment","tag-plugin-en"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/posts\/12620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/comments?post=12620"}],"version-history":[{"count":0,"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/posts\/12620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/media\/12623"}],"wp:attachment":[{"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/media?parent=12620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/categories?post=12620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vipestudio.com\/en\/wp-json\/wp\/v2\/tags?post=12620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}