Programmatically rewriting slug through functions.php but returns 404

You can try this plugin, I think this will work for you. You can directly change the URL on your page by clicking on URL to whatever you want.

Hope this would be helpfull.