Detect the browser preferred language

  1. When the language is set from the content, the directory name or from subdomain names
  2. When using multiple domains

1. When the language is set from the content, the directory name or from subdomain names

Go in Languages > Settings

Note that this option works when the language is chosen from the content, from the directory name in the url or from the subdomain.

The detect browser language option in the Polylang settings.

When activated, someone visiting your homepage for the first time is redirected to the homepage in the language according to his browser preferences. If his browser preferences do not include any language of your site, the default language is used.

Polylang sets a cookie for returning visitors to be redirected to the homepage in their last browsed language. Thus, if you want to test the functionality on your site, don’t forget to clear your cookies between each test.

Here are some examples with French as default language:

detect-browser-language-chromium-1

Case 1: None of the browser language preferences of your visitor match the website languages. The visitor is redirected to the French home page (default language). If his last browsed page is in English, he will be redirected to the English homepage at the second visit.

detect-browser-language-chromium-2

detect-browser-language-chromium-3

Cases 2 & 3: In both cases, English is the first language in the browser preferences of your visitor which matches one of your website languages. The visitor is redirected to the English home page.

Note: If you don’t want any redirection to occur, you must deactivate the browser preferred language detection and hide the default language code in URLs by checking the relevant option in the URL modifications settings.

2. When using multiple domains

It used to be possible, with Polylang Pro and SSL, for this option to work when using multiple domains. Unfortunately this feature was recently broken for a multiple domains setup due to new browsers’ parameter expectations.

A ticket was opened to try and move forward towards fixing it. While awaiting the resolution of this ticket, a solution is to use https://github.com/ikovacic/polylang-pro-sso-fix.