In this post
Redirecting visitors to their own language preference based on browser language or IP address is a feature often requested by our TranslatePress users. This can be easily achieved using the Automatic User Language Detection add-on.
Below we’ll go through the reasons for using automatic user language detection as well as how it’s implemented in TranslatePress.
Why Automatic User Language Detection Matters
First-time visitors expect to see the website in a language they understand. With such a short attention span it’s easy to lose users who are not finding the language switcher soon enough. This is why it is important not only to have their language available, but to also point this out to them or even automatically redirect to it.
The way automatic language detection works is that the last visited language is remembered through a cookie, so returning visitors will always visit your website directly in their chosen language.
With the Automatic User Language Detection add-on active, first-time visitors whose browser settings or IP reveal a language different than your site’s default one, will be prompted with a pop-up or a hello bar giving them the option to switch to their automatically detected language.
Alternatively, you can set the functionality up so that your website automatically redirects the user to their language, without a prior notification. However, this could affect your site’s indexing, because of Google’s frequent algorithm changes, hence why we recommend choosing the first option.
How Automatic User Language Detection Works in TranslatePress
The Automatic User Language Detection add-on works out-of-the-box, with no required setup steps.
There is no need to register for IP address language services, because the language recognition based on IP happens locally with the help of GeoLite2 databases from MaxMind.
There are two ways of finding out what languages the visitors speak: either by browser language setting or by IP address. In the community, the browser language is seen as the most reliable information, but it depends on who your targeted audience is in order to decide which works best for your website.
If you want to change the default setting of taking into account the browser language first and then IP address, you can do so with a simple select found in Settings → TranslatePress → Advanced. You can choose to determine language based solely on IP address or solely on browser language, or a combination between these two.
Next, you can choose whether you want your visitors to be notified via a pop-up or hello bar about the language detection, or if you want them to be redirected right away. Then you can move on to customizing the messages to be displayed.
Here’s a short video tutorial that takes you through everything you need to know in order to enable automatic user language detection on your WordPress site:
Hard Redirects vs. Soft Redirects: A Technical Issue
When we use redirects, w e chose not to have any hard redirects in place for several reasons. Hard redirects, meaning those that happen on the server side, simply do not work with caching systems, be it a WordPress plugin, or host caching system. The page served from cache would not take into account the correct language for each visitor, since the code on the server never gets executed.
Caching is not the only problem with hard redirects. It also requires users to have their browsers accept cookies and allow JavaScript to run. Otherwise it would not allow users to switch language since it would keep redirecting to the initially detected language.
So how is our add-on solving all of these issues caused by the hard redirects?
The Automatic User Language Detection add-on uses only soft redirects, which happen on the client side. But there’s a problem: finding out the language preference sent by the browsers through the Accept-Language request HTTP header can only be read on the server side. The solution is to make a fast custom ajax request internally to get our needed information, all without using the slow-loading WordPress environment.
The browsers that do not accept cookies or prevent JavaScript from running, will still allow users to manually switch to their desired language.
A Well-Thought-Out Language Detection Solution
The final result is a versatile and fast solution, that works extremely well with a wide range of environments seen both on server side and on client side.
See how you can take advantage of the Automatic User Language Detection Add-on and other useful features that TranslatePress offers.
TranslatePress Multilingual
Do you have any more questions about automatic user language detection? Let us know in the comments below.
If you found this post helpful, please check out our YouTube channel, where we constantly upload short & easy-to-follow video tutorials. You can also follow us on Facebook and Twitter to be the first to know each time we post.
Related: Multilingual SEO on WordPress – 7 Tips to Rank In All Languages
[…] website instead of them going to the local competition. First-time visitors to your webpage will be automatically redirected to your page in the language they need to see it in, without you having to lift a finger. They […]
[…] as the title says – you’ll get to insert language detection based on your visitors IP changing the language of your site to the native language of the visitor […]
[…] Automatic user language detection […]
This addon makes an infinite redirection loop when you activate it. Can you fix that?
Hi Guillermo,
First make sure you have the latest version of the add-on.
If that didn’t fix your issue, try briefly switching your theme with a default WordPress theme. If the issue is gone, check to see if your theme is adding the language attributes in the html tag like this:
html class="no-js" ... language_attributes();
You can reach out to our support if the issue persists and I’m sure we’ll get to the bottom of it.
Do you WANT your theme to use language_attributes() or no? Your statement is unclear.
I use automatic language detection.
The Ukrainian language is determined correctly. But when you try to go to the internal pages, it redirects to Russian.
And it shouldn’t be.
Support has not responded for 8 days.
can someone why this may cause index issues?
thanks
Redirect directly (*not recommended)
Choose if you want the user to be redirected directly.
* Not recommended because it may cause indexing issues for search engines.