SyntaxFix
Write A Post
Hire A Developer
Questions
I don´t know how to do it using code, but for those who don't mind using a plugin. This is a great one that works for me:
https://es.wordpress.org/plugins/permalink-manager/