URL for XML should be generated after permalinks are applied
2
votes
sending a url to Google that needs to redirected once it hits your website isn't a great answer. In your code, if you use the native function, get_permalink() per https://developer.wordpress.org/reference/functions/get_permalink/ then the URLs you are sending in the XML feed would be correct