wordpress-attachment-page-redirect

Disable WordPress attachment pages

WordPress has many small problems and one of them is, in my opinion, the attachment page for pictures. For each uploaded image, WordPress creates automatically a separate page. On this so-called attachment page, there is nothing to see, except the picture itself. This can make sense for photographers or in a portfolio, but not in a normal blog or magazine.

On the contrary, Google also detects such sites and redirects users to them without them finding any real added value there. And what does the user do who does not find anything with added value on a page - right, he leaves the page again and this sends less optimal user signals to Google.

And that is not all! Every attachment page is a new URL in the Google Index. In plain language this means that you push unnecessarily many URL`s into the index and they are indexed by Google which can also have negative effects on your whole website.

Unfortunately, the attachment pages in WordPress cannot be switched off by default, so I would like to explain various options in today's article to help you solve this problem.

wordpress-attachment-page-redirect

1. redirection via Yoast SEO

With the world's most used SEO plugin from Yoast the whole thing is done in 3 steps:

  1. Under the yoast options click on "Display in search".
  2. at the top of the tabs click on Media
  3. Here the button should be set to "yes

yoast deactivation appendix pages

 

2. redirection via wpSEO

Also with the well-known and from us much praised SEO Plugin wpSEO this setting is available and quickly implemented.

  1. under wpSEO options click on indexing
  2. then scroll down a bit and here you will find the option "Redirect attachment pages to attachment" and can activate it

disable the wpseo attachment

3. redirection via Plugin Attachment Pages Redirect

This plugin has no options or settings, it just performs a simple redirection once it is activated.

Important. Unlike Yoast and wpSEO this plugin redirects the attachment URL to the actual post where the image was published.

I am of the opinion that a forwarding to the actual graphic is the better solution.

Download Attachment Page redirect

4. redirection via entry in the image.php

Simply create a file named image.php with the following content:

post_parent));
?>

...Then copy the image.php into your theme folder.

5. redirection via entry in functions.php

Copy the following code into your functions.php. For your information, this code also does not lead directly to the image but to the post page.

function fastwp_redirect_image_page() {
  global $post;
    if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) {
      wp_redirect(get_permalink($post->post_parent), 301); /* Redirect to post parent */
      exit;
    } elseif ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent < 1) ) {
      wp_redirect(get_bloginfo('wpurl'), 302); /* Redirect to home page if not associated to any post/page */
      exit;
    }
  }
add_action('template_redirect', 'fastwp_redirect_image_page', 1);

Forwarding as a solution

These solutions now ensure that attachment pages either redirect to the respective mail or directly to the graphic. In any case, there is no more nonsense about attachment pages in WordPress.

Especially for blogs and small magazines, the solutions are therefore a real added value.

Do not index WordPress images

A deeper reason for this option is not immediately apparent to me, but surely there are some who need this solution.

The best way to do this is to use robots.txt and specify exactly what you do not want to be indexed. Here are some options:

1. Exclude the entire upload folder of WordPress from indexing.

User-agent: Googlebot image
Disallow: /wp-content/uploads/

 

2. exclude certain images from indexing

User-agent: Googlebot image
Disallow: /wp-content/uploads/2019/my-picture.jpg

 

3. exclude certain types of images from indexing

User-agent: Googlebot image
Disallow: /*.gif$

 

4. if you want to exclude everything consistently and possibly use your own upload folders / paths

User-agent: Googlebot image
Disallow: /

Update: June 2, 2019

About Christian

My name is Christian and I am co-founder of the platform fastWP. Here in the magazine I am responsible for the more "technical" topics but I like to write about SEO, which has been my passion for over 10 years now.

1 thought on “Anhang-Seiten für Bilder deaktivieren”

  1. Hello, Christian,

    ich habe eine Frage zum Punkt 5 (Umleitung mittels Eintrag in der functions.php):
    Hat es einen bestimmten Grund, wieso auf die Beitragsseite mit 301 und auf die Hauptseite mit 302 umgeleitet wird?

    Greetings
    Torsten

Leave a Comment

Your email address will not be published. Required fields are marked *

en_GB