Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client needs a feature where if a user is not from the main country, the website should use English as a fallback language, regardless of the browser language.
Solution:
We explained that while WPML does not have a built-in feature for this specific redirect behavior, it is possible to achieve this by using WPML's hooks for a custom solution. We provided two hooks that could be useful:

We also suggested exploring general web development techniques for detecting a user's browser language and implementing redirects, referencing a StackOverflow thread for guidance.

We recommended backing up the website before implementing any custom code. If the client is not comfortable with custom coding, we suggested reaching out to one of our certified contractors for professional assistance.

If this solution does not apply or is outdated, or if further assistance is needed, we encourage the client to check the related known issues, verify the version of the permanent fix, ensure the latest versions of themes and plugins are installed, and if necessary, open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by Mateus Getulio 1 year, 3 months ago.

Assisted by: Mateus Getulio.

Author Posts
March 5, 2024 at 2:21 pm #15374965

johannesG-17

Hi,

I've found the following tutorial: https://wpml.org/documentation/getting-started-guide/language-setup/automatic-redirect-based-on-browser-language/

Sadly, this is not what I exactly need. I need some kind of setting where I setup something like:

“If the user is not from my main country, use language X as fallback”.

So in my case, I want to always change the browser language to English, in case the user is not using a German browser.

Is this possible? If yes, how? If not, can it be implemented?

Thanks!

March 5, 2024 at 9:30 pm #15376579

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Thank you for reaching out with your question. While WPML doesn't offer a built-in feature specifically meant to the redirect behavior you've described ("If the user is not from my main country, use language X as fallback"), it is possible to achieve your goal by relying on WPML's hooks for a custom solution.

For a start, you might find these hooks particularly useful:

- https://wpml.org/wpml-hook/wpml_browser_redirect_language_params/: This allows you to customize the conditions under which the language redirection occurs. You can use this to set up your fallback language based on the user's country.

- https://wpml.org/wpml-hook/wpml_enqueued_browser_redirect_language/: This hook lets you control whether the browser language redirect script should be enqueued. It can be part of your strategy to manage redirects more closely.

If you're comfortable with custom coding, you might also explore general web development techniques for detecting a user's browser language and implementing redirects, such as the method discussed in this StackOverflow thread: https://stackoverflow.com/questions/37918620/detect-browser-language-and-redirect-to-another-url

Before implementing any custom code, I strongly recommend backing up your website, including the database. This ensures that you can restore your site to its previous state if anything doesn't go as planned.

If custom coding is outside your comfort zone, or if you prefer professional assistance to ensure everything is set up perfectly, consider reaching out to one of our certified contractors: https://wpml.org/contractors. They have the expertise to work with WPML and fit your exact requirements, including implementing custom redirect behaviors like the one you've described.

We're here to help, so if you have any further questions or need additional guidance, please don't hesitate to ask.

Best regards,
Mateus

March 5, 2024 at 9:30 pm #15376580

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Thank you for reaching out with your question. While WPML doesn't offer a built-in feature specifically meant to the redirect behavior you've described ("If the user is not from my main country, use language X as fallback"), it is possible to achieve your goal by relying on WPML's hooks for a custom solution.

For a start, you might find these hooks particularly useful:

- https://wpml.org/wpml-hook/wpml_browser_redirect_language_params/: This allows you to customize the conditions under which the language redirection occurs. You can use this to set up your fallback language based on the user's country.

- https://wpml.org/wpml-hook/wpml_enqueued_browser_redirect_language/: This hook lets you control whether the browser language redirect script should be enqueued. It can be part of your strategy to manage redirects more closely.

If you're comfortable with custom coding, you might also explore general web development techniques for detecting a user's browser language and implementing redirects, such as the method discussed in this StackOverflow thread: https://stackoverflow.com/questions/37918620/detect-browser-language-and-redirect-to-another-url

Before implementing any custom code, I strongly recommend backing up your website, including the database. This ensures that you can restore your site to its previous state if anything doesn't go as planned.

If custom coding is outside your comfort zone, or if you prefer professional assistance to ensure everything is set up perfectly, consider reaching out to one of our certified contractors: https://wpml.org/contractors. They have the expertise to work with WPML and fit your exact requirements, including implementing custom redirect behaviors like the one you've described.

We're here to help, so if you have any further questions or need additional guidance, please don't hesitate to ask.

Best regards,
Mateus