Answer the question
In order to leave comments, you need to log in
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
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' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question