Created
October 25, 2022 11:38
-
-
Save patrickposner/7083c94789c2de2d90de6b9240ce588a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", function () { | |
const language_links = document.querySelectorAll('.wpml-ls-link'); | |
for (const language_link of language_links) { | |
language_link.addEventListener('click', function handleClick(event) { | |
event.preventDefault(); | |
let languages = this.getElementsByClassName('wpml-ls-native'); | |
for (const language of languages) { | |
let language_tag = language.getAttribute('lang'); | |
let language_href = language.parentElement.getAttribute('href'); | |
// Delete old WPML cookie. | |
document.cookie = 'wp-wpml_current_language=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'; | |
document.cookie = '_icl_visitor_lang_js=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'; | |
// Set new cookie for selected language. | |
document.cookie = 'wp-wpml_current_language=' + language_tag; | |
document.cookie = '_icl_visitor_lang_js=' + language_tag; | |
window.location.href = language_href; | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment