The-seo-framework: Automatic redirection to the parent post for attachment page

Created on 28 Jan 2017  路  12Comments  路  Source: sybrew/the-seo-framework

Hello there,

As described here : https://wordpress.org/support/topic/about-feature-suggestions-2/#post-8689603 I have seen that a great feature was actually lacking in The SEO Framework : an automatic redirection to the parent post for attachment page.

This feature was available in my previous SEO plugin, and I really lack a such feature. I hope a free extension will be added for it asap.

The main advantage of this is that peoples who find images on google images & co will imediately be redirected to the post where the attachment is attached.

Cheers.

[Extension type] Free [Status] In progress [Type] Enhancement

Most helpful comment

All 12 comments

Hi @Moxymore,

What do you think the steps would be for executing this, in layman's terms?

Keep in mind that both Google & the visitor must experience the same behavior when accessing a page; otherwise you're cloaking. Keeping this in mind I find it hard to imagine a way to solve this; although I really do like the idea!

Hi @sybrew,

I'm not an SEO expert, and even not a good dev at the moment since I have started to code 10 months ago. That's said, I can't properly (even in layman's terms) describe the steps to implement it in a good manner in order to don't cloak. But I'll try to explain a bit, and considering that crawlers are not stupid.

In the Wordpress architecture, each attachment has a dedicated page, which is rarely used by the webmaster for styling purposes... In short, this post is actually not created to be displayed on the frontend (imo) but more in order to collect the images datas (meta description, alternate text for screen readers etc). That's why a such feature can be really usefull, by redirecting the user to the parent post (the post where is attached the attachment).

Technically, the best thing to do is to look at the code of All In One SEO, which is a free wordpress plugin, and see how he achieve this operation. Combined with your expertise, you'll be able to conclude if it's a good or bad practice, SEO speaking.

Now, regarding crawlers, I think a such option can damage some website if they doesn't fill the attachment metadatas, which are the only information a crawler can read in order to see if it's a related content or not. The minimum requirement is to have this attachment visible in the final url, at least.

In my case, I have added an upload action, which automatically put the title of my parent post in the metadata's image. Considering crawlers aren't stupid, they will see that the attachment is present in the final url +has similarities to the final destination url, and will probably say "OK! It seems to don't be a cloak."

I'll conclude by a point, and that's why someone more experienced than me should look at All In One SEO plugin code : google image never told me that my images where redirected... I have sees in the past other image where google told me "warning, this site is trying to redirect you". Then I think that it's not a redirection, but something more like a regex url rewrite on the fly.

I hope this will help a bit, at least. I'm learning every day, but can't do more yet.

Cheers.

The wrong implementation.

Reads AIOSEO code... _notices over 6200 code quality warnings and sees no documentation_ 馃棥

Anyway, after some deep digging, I've found that they take the post's parent title and put in in place, this is not optional. This is also a good way to get duplicated page titles, a common warning signal in Google Webmasters, for a good reason: pages must be unique in their titles and descriptions.

Attachments are useless.

Effectively, I know attachment pages are useless for SEO, therefore the attachment pages have noindex set to them by default:

image

What would be the solution is Article Schema.

See #21.

In Google's Documentation it shows that it allows for images to be defined.
This will only work for the Featured Image or the Custom Social Image URL.

It's currently being programmed as extension.

image

I will need to look into this on how this affects Google Images.

And another solution on the side: Microdata

See Google+ Structured Data.
Google has no documentation on how this could affect Google Images, but if WordPress would allow attachment insertions to be manipulated - this would be great.

With all that:

If the above is properly implemented, we could simply redirect the images to the first parent's post.
This would effectively remove the image page from search.

However, I couldn't find any Google Documentation regarding the image search. So this should be tested beforehand.

In conclusion:

There's still a lot to be tested before we can safely implement redirection without losing images from Google Image Search.

But I think you might like the direction we're heading at already 馃槃

Articles have already been released. The next step is to implement your suggestion.

This is what's planned:

  1. Activate the planned extension.
  2. All attachment pages (with a parent page attached to them) will then 301 redirect to the parent page.
  3. That's it 馃槃

I do not want this to result in attachments being lost from Google Images. So testing is required prior to release.

@sybrew: So with the next release this new attachment redirection feature would be implemented?

Hi @strarsis

When an issue is marked closed, it's either invalid or already implement within the GitHub release.
When an issue is still marked open, it's either still under consideration or being worked on.

At the moment, this issue is under consideration.

It will take at least a months worth of testing before it can be released to the public, because I do not know whether nor how such implementation will affect Google's image index.

@strarsis if you are coming from Yoast SEO, that function is literally just a few lines of code:

    /**
     * If the option to redirect attachments to their parent is checked, this performs the redirect.
     *
     * An extra check is done for when the attachment has no parent.
     *
     * @return boolean False when no redirect was triggered
     */
    function attachment_redirect() {
        global $post;
        if ( is_attachment() && ( ( is_object( $post ) && isset( $post->post_parent ) ) && ( is_numeric( $post->post_parent ) && $post->post_parent != 0 ) ) ) {
            wp_safe_redirect( get_permalink( $post->post_parent ), 301 );
            exit;
        }

        return false;
    }
add_action( 'template_redirect', 'attachment_redirect', 1);

That's all that Yoast does when you check that box. Keep in mind, this does nothing with unattached items in the media library. Those will still have a reachable attachment page.

In our case, we hate attachment pages. They are useless to visitors and search engines on our site and don't off any value over the regular posts with the media inserted, so we disable all of them with a 404, rather than doing this redirect.

That function is unnecessarily complex! Is that really from Yoast?

Fixed:

function attachment_redirect() {
    global $post;
    if ( is_attachment() && ! empty( $post->post_parent ) ) {
        wp_safe_redirect( get_permalink( $post->post_parent ), 301 );
        exit;
    }

    return false;
}

Quick Update:
Google seems to look into Open Graph meta tags.

So, the attachment results' links will point to the correct pages; with or without our influence.
Provided that you use the same OG image as the Featured Image, aside from the fact for if you wish to index attachment pages or not.

Indeed, that was directly from Yoast

This extension is next in line.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

9585999 picture 9585999  路  5Comments

Hube2 picture Hube2  路  3Comments

epgunn picture epgunn  路  3Comments

samburgers picture samburgers  路  6Comments

Ciantic picture Ciantic  路  5Comments