A
A
Alexey selftrips.ru2018-03-22 19:24:34
WordPress
Alexey selftrips.ru, 2018-03-22 19:24:34

How to redirect attachment pages?

It seems to be bad for search engines that wp creates separate pages for attachments.
The All in one seo pack plugin has an option to redirect the addresses of such pages to the post page itself.
But I found that if the image is not attached to any post, then the redirect does not occur. (for example, there could be a redirect to the main page)
1. Is this a problem?
2. How to solve it (how to disable attachment pages completely)
3. Why might they even be needed by someone?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2018-03-22
@selftrips

Hello!
Yes indeed it won't redirect the unpinned image.
You can decide.
Plugin - https://wordpress.org/plugins/redirect-unattached-...
Code:

function attachment_redirect() {
    global $post;
    if ( is_attachment() && ( $post->post_parent == 0 ) ) {
        wp_redirect( get_permalink( $post->post_parent ), 301 );
        exit();
    }
}
add_action( 'template_redirect', 'attachment_redirect' );

Source - https://wordpress.stackexchange.com/questions/1595...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question