Thank you!
I did add the following to the theme’s functions.php file, with “mc” being the parameter key I want recognized:
function add_query_vars_filter( $vars)
{
$vars[]=”mc”;
return $vars;
}
add_filter( ‘query_vars’, ‘add_query_vars_filter’ );
I realize there may be a way to do this all in php, but the parameter won’t persist if the visitor starts a new session, which is why I’m sticking the parameter in localStorage with Javascript.
The localStorage object is being created successfully, and when I open the console, the link that I want changed has an href property which does contains the parameter:
h ttps://xxxxxxxxxxxx/Account/Login?code=xxxxxxx&mc=6540
however, the innerHTML is not successfully having the parameter appended:
a href=”https://xxxxxxxxxxxx/Account/Register?code=xxxxxxx”>Apply Now</a
I will take a look at the links you gave to see if I’m missing anything. Like I said, on our straight HTML, CSS and Javascript site, this works perfectly:
function getAllUrlParams() {
//assign URL parameters to variable
console.log(“URL Params loaded”);
var queryString = window.location.search.substring(1);
if (queryString) {
//split queryString into pairs
var pairs= queryString.split(‘&’);
console.log(pairs);
//split pairs into object
var result = {};
pairs.forEach(function(pair) {
pair = pair.split(‘=’);
result[pair[0]] = decodeURIComponent(pair[1] || ”);
});
//check localStorage to prevent overwriting values, write values if empty
if (localStorage.getItem(‘brazosMC’) == null) {
localStorage.setItem(‘brazosMC’, JSON.stringify(result));
}
}
var elements = document.getElementsByClassName(“apply”);
var i = elements.length;
console.log(elements);
var params = JSON.parse(localStorage.getItem(‘brazosMC’));
console.log(params);
if (params !== null) {
if (“mc” in params) {
var url = “https://xxxxxxxxxx/Account/Login?code=xxxxxxx” + “&” + “mc=” + params.mc;
while (i–) {
elements[i].href = url;
}
} else {
console.log(“Key undefined”);
}
}
}
-
This reply was modified 7 years, 11 months ago by
jwgreen1976.
-
This reply was modified 7 years, 11 months ago by
jwgreen1976.