Tutorials

How to disable image attachment pages on WordPress

disable image attachment pages on WordPress

Looking for a way to disable image attachment pages on WordPress website? Here in this article, we will show you the easiest way to disable image attachment pages on your WordPress website.

Image attachment pages are looking like incomplete pages and when the visitors land on this type of image attachment page it will create a negative impression. Users leave these types of pages immediately and never come back. It’s very harmful to your website to have image attachment pages. So let’s see how you can disable it easily.

Why it is important to disable image attachment pages

When you upload anything in your media file WordPress will automatically create a single page for this media file. Every media file on your website has a separate page. This type of attachment page is not useful for most users and they don’t want to see this type of page. Most of the WordPress themes don’t provide any special template for these attachment pages.

It’s not a very good practice because sometimes an image on your website may get popular. People will find that popular image on Google or other search engines and land on the attachment page. It will not be the proper way, the user needs to land on the main post page, not the attachment page.

Disable image attachment pages on WordPress

There are two ways to disable image attachments in your WordPress website. You can disable it by code snippets or using a plugin. Here we will show you both ways.

Disable image attachment with code snippets

Using code snippets is the easiest and quickest way to disable image attachment pages.  In this method at first create a theme folder as image.php. Most of the theme has the image.php file, so if the file exists you need to edit it. After that add this little code snippet at the beginning of the file.

<?php wp_redirect(get_permalink($post->post_parent)); ?>

Save the file and upload it to your theme directory. This code will redirect your attachment page to the main post.

Disable image attachment with a plugin

If you are not comfortable with using code snippets then you can use this method. There are a few plugins that offer you to disable the attachment pages. Here in this tutorial, we are using the All in One SEO WordPress plugin. 

Install and activate the plugin and then go to All in One SEO > Search Appearance page. Now move on to the Image SEO tab and set the Redirect Attachment URLs as Attachment Parent. At last click on the Save Changes button to save the changes.

This will allow the user who landed on the images attachment page to the main article page.

Wrapping Up

Following the process, you will be able to disable the image attachment page on your WordPress website. You can see our other articles to learn How to upload select and change post-thumbnail easily in WordPress

How to change the font size in WordPress easily

How to split WordPress post into multiple pages

We hope this article will help you. If you like this article please like our Facebook Page to stay connected.

You Might Also Like