I am trying to add URL parameter to all the URLs of Wordpress website.
This is for tracking affiliate sales by tracking links.
E.g. I have put a link on another website
http://website.com/?aff=abc
When a person comes to my website via that link the parameter stays in the URL but as soon as the person goes to another page on my website the URL parameter is gone.
I want to keep the parameter in the URL no matter what page the user is on.
I found the following code that works but it works for only one parameter.
function wprdcv_param_redirect(){
if( !is_admin() && !isset($_GET['aff']) ){
$location = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$location .= "?aff=abc";
wp_redirect( $location );
}
}
add_action('template_redirect', 'wprdcv_param_redirect');
Is there a way to modify the above code to have any value in the parameter variable? Right now the value "abc" is fixed for the variable.