I am making a simple landing page that uses English as its primary language (the main version is set as the homepage). However, if we detect that a visitor has a Polish browser, we want to redirect them to the Polish version of the site.
I tried a few solutions from the forum, but they didn’t work - the last one I tried was:
Hi @Kacper_Bieda as you see in image language request returns string in format "en-gb"(on my computer) and your condition contain only two letters. IMO you can use RegEx or slice to compare these first two letters. Something like this
I appreciate your help, thanks! It’s a shame, but I am a complete idiot when it comes to javascript or just coding - know only the basics of CSS & HTML - I would be grateful for being more specific. To be honest, I found this custom codes hoping that it will be working easily, but it can’t be so easy.
Thanks! I tried this one, but now it’s showing website only in English version and there is no redirection at all.
I have just a thought, that maybe I’m placing this custom code in wrong place - I am adding it in custom code area for the main page in section before .
Since this is a global code for any page of your website, head to the Project Settings > Custom Code > and paste in in the </body> tag section. This will now run on all pages for you.
It’s working now, but just in case - when I’ve pasted it in project settings custom code the website was refreshing all the time.
Heading to solution:
Code from you works perfectly fine! Thanks.
It was working all the time, turned out that from some reason it treats my browser (which is in Polish) as English, but on every other device with Polish language the redirection is working perfectly fine.
To make the website stop refreshing, I had to put it back to before </ body> tag on the homepage custom code.