Here is a snippet on how to turn all of your posts to new permalink structure without affecting other post types.
In this example I changed all my posts to have /blog/ in url.
This snippet should be added somewhere in your functions.php file.
You might bump into a problem with ‘Redirect loop’ after you add this code.
If you encounter that problem, just delete all from L31 > L45.
After adding these functions if you don’t do a redirect form ‘old url’ > ‘new url’, your posts will be accessible on both url’s, and from SEO point of view this is not good for you.
1. Duplicate content issue
2. There might be some links out there pointing back to your posts, and this is why you shoud 301 redirect them to new location.
Hello Bob, I used your code but edit link at front of post url in Post Page is disabled! why?
I’m not sure I understand what you mean?
Is that work for you ?
I am also facing the same issue.
Can you share screenshot, I’m not sure I understand what is this about?
Thanks for replying.
Please see these screenshots:
If not using your code – http://prntscr.com/lxvfj1
If using your code – http://prntscr.com/lxvfw8
Thanks. Haven’t seen this so far.
Not sure why is this, but I believe you should be able to change slug on ‘Quick edit’ when viewing list of posts.
That could do as a workaround?
I get this work now.
Just use this.
Thanks, I’ve updated the code accordingly.
Or maybe it could work if you just do:
if ( is_admin() ) return $url;
Blog previews are not working
it only works after I published and unpublished it. Can you try with a new blog post? Hit preview.
And when I removed that code (blog prefix) everything works fine.
Please have a look into this issue ASAP
Hi, sorry but atm I don’t have time to check on this.
How would you modify this for a different permalink structure? The client’s old site used /blog/year/month/day/postname.
Try just changing your permalinks under settings > permalinks. It might work with any of these too.
Awesome, was worried about all my old posts not redirecting.
Great and concise info, thanks!
After I change the permalinks structure under Settings, my custom post type archive gets 404 not found error… Any ideas?
Not sure, would need to investigate deeper. Probably best way would be trial & error.
This was a life saver, thanks!
Glad I’m able to help.
Hi, thanks for this code.
The categories permalinks have not been rewritten. How can I fix it ?
Hi Nicolas, this doesn’t rewrite categories permalink structure only single post.
Thanks for this code,
i was Modify post link /blog/post-name instead of /post-name. But coming to AMP pages not working. its getting 404 error page.
How to fix this type issue?
I was Modify post link /blog/post-name instead of /post-name with custom code.
Page working fine. BUt AMP pages not working. getting 404 error
PLease check this links
Can you please help me on this issue?
I’m not sure is this some caching issue maybe?
And depends which plugin are you using.
Personally I haven’t tried so I’m not be able to give any advice at this moment, sorry.
Worked flawlessly on my website. Thank you!
Glad you found it helpful.
This is just fantastic. Just tested it on my develpment server and in works like charme.
Thank you for sharing this live saving info.
Thanks. Deep bow back
This is perfect, thanks mate!
When I do this I get a category 404 error
article: https://localhost/blog/example-article – ok no problem
category: https://localhost/blog/examplecategory – 404 The page you are looking for was not found
Thanks, it saved my time. This works well.