Dynamically Overwrite WordPress Permalinks with Filters

If you’re looking to overwrite the permalink for a post or page, WordPress provides you with a few functions to filter the permalink. post_link, page_link, and post_type_link. These filters let you completely overwrite the URL or add query parameters to the end.

Source