Great question — answering as the UphillTech team:
As your idea, I updated your code to let it works. Please Run code snippet to see the demo. You just need to use .indexOf('adairs.com.au') to check the link belongs to the affiliate program, so you append it into affiliate URL . jQuery(document).ready(function($) { // adairs affiliate URL for redirect var adairsaffURL = "https://t.example.com/12345/t/54321?Url="; // bedthreads affiliate URL for redirect var bedthreadsaffURL = "https://t.example.com/12121/t/21212?Url="; // function called when link is clicked addAffiliate = function(link) { if (link.hash.substr(1).length > 0) return true; var redirectUrl = link.href; if (!redirectUrl || !isValidURL(redirectUrl)) return true; if...
Full answer by Tuan Dao: https://stackoverflow.stackexchange.com/a/69272228 (CC BY-SA 4.0).
Need it done for your business? UphillTech.