When you have jquery:
$(document).ready(function(){
function setmyCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getmyCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(";");
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == " ") {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
$('a.nturl.single-language.es').click(function () {
setmyCookie("mylng", "es", 365);
});
$('a.nturl.single-language.en').click(function () {
setmyCookie("mylng", "en", 365);
});
$('a.nturl.single-language.nl').click(function () {
setmyCookie("mylng", "nl", 365);
});
mylng = getmyCookie("mylng");
if (mylng == "") {
mylng = "es";
}
if (mylng == "es") {
window.setTimeout(function() {
$('a.nturl.single-language.es').click();
}, 0);
}
if (mylng == "nl") {
window.setTimeout(function() {
$('a.nturl.single-language.nl').click();
}, 0);
}
});
And if you’re trying to figure out the functionality;
The links are from a plugin and a click also activates a language. This script just adds another click-hook to save the language in a cookie, and also activate the chosen language on every page load.
That’s all!