Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I change my permalink structure successfully.

/%year%/%monthnum%/%postname%/ --> /%category%/%postname%/%post_id%/

But now I face a problem. Before change my permalink, I redirect my attachment url to parent post url through Yoast seo plugin and it works well. But after changing permalink structure, it doesn't work and show so many not found errors.

Attachment redirection works only for my new permalink structure but not for old permalink sturcutre,

I also follow this step and it works well. But my issue is little bit different. My permalink structure was /%year%/%monthnum%/%postname%/ before 21st January, 2013. I redirected Attachment url to parent post url through Yoast's seo plugin and it works. But after 21st January, 2013, I change my permalink structure. /%category%/%postname%/%post_id%/ and I redirect my old permalink structure to new permalink structure. (with Simple 301 Redirects plugin)

I uncheck Attachment url to parent post url in Yoast's seo plugin and then once again check the box of Attachment url to parent post url. So that refresh Yoast's seo plugin and it works normally. But it works only with new permalink structure (/%category%/%postname%/%post_id%/), not working with the old permalink structure(/%year%/%monthnum%/%postname%/). And therefore it is result in so many 404 errors.

Attachment url to parent post url is working only for those post which I published after 21st January, 2013. Before this date I published almost 594 post and for all those post, Attachment url to parent post url doesn't work.

so kindly request you, please suggest me, how to solve this issue. How to redirect attachment url to old parent post url?

share|improve this question

2 Answers 2

After changing your permalink structure, you need to refresh the settings in your Yoast plugin.

  1. After changing your Wordpress permalink settings, go back to the Permalinks section for Yoast (Yoast SEO => Permalinks).
  2. Uncheck the box to "Redirect attachment URL's to parent post URL."
  3. Click Save.
  4. Check the box again.
  5. Click Save again.

This should reset the permalink structure as identified by the Yoast plugin, and your attachment pages should redirect properly now.

share|improve this answer
    
I follow your guidelines but attachment redirection for old permalink structure doesn't work. any other solutions? –  livewireworld Feb 14 '13 at 1:16

Please add to your theme's functions.php:

add_action( 'template_redirect', 'wpsites_attachment_redirect' );
function wpsites_attachment_redirect() {
    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 );
        exit();
    endif;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.