preserve url parameters from affliliate sites


Please help,

I am using a wp site as medium between e.g. a news site lets call it A and the actual site that e.g. sells a particular product lets call it B.

A —- medium site — B

news site —- wp — product site

What I need is to keep 2 url parameters from site A to site B.
A good example that illustrates the above is the news site has an article for NBA on site A
one of the links is an advertisement e.g. for basket shoes.
If a customer clicks it goes to the wp medium site where he can chooses color, style and etc… then if he decides to buy something it is redirected to site B.

What I need and it is crucial is that the wp site passes on the 2 url parameters from the initial link on site A

What I was thinking was for the wp site whenever it sees an “a href” to add the parameters from variable 1 and variable 2 so all the links are having those 2 parameters and pass them on.

Can I use the following script?

function getQueryParams(qs) {
qs = qs.split("+").join(" ");
var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
    params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
} return params;}

var query = getQueryParams(;
$('a').each(function () {
var href = $(this).attr('href');
if (href) {
    href += (href.match(/?/) ? '&' : '?') + 'affiliate=' + query.affiliate + '&pname=' + query.pname;
    $(this).attr('href', href);


The 1st part makes all the url texts utf8 and not % encoded and the second part should pass on the 2 variables in concern.

Please help where I should place it and how I should call it?

, kan1 1 year 2020-07-24T04:11:00-05:00 0 Answers 49 views 0

Leave an answer