Global Content Area, Selective Exclude for Language Switching

The code below is set up to detect English, German and French. You can add as many languages as needed. Be sure to use the industry-standard ISO language codes which you can find HERE.

<script type= "text/javascript">
var language = window.navigator.language;
  
if(language == "en-US" || language == "en-“gb || language == "en-CA"){
window.location.href = "www.yoursite.com/en";
}

else if(language == "de" || language == "de-at" || language == "de-li" || language == "de-ch" || language == "de-lu"){
window.location.href = "www.yoursite.com/de";
}

else if(language == “fr” || language == “fr-be” || language == “fr-ch”){
window.location.href = "www.yoursite.com/fr”;
}       
</script>

The above code should ONLY be added to the root index page, not the language variants. This will prevent visitors getting stuck in a loop if they get switched to another language variant of your page. It is also advisable to make a duplicate of the main index page WITHOUT the autodetect code (call it home.html) and have all your home site links point to that version of the home page. Again, this is to prevent visitors getting redirected a second time if they return to your main home page URL.

4 Likes