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?

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.

  • I follow your guidelines but attachment redirection for old permalink structure doesn't work. any other solutions? Feb 14, 2013 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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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