At Freshy, we routinely help WordPress site owners troubleshoot advanced plugin and redirection issues. In this guide, we’ll show how we resolved a problematic language redirection loop on a multilingual WordPress website using Weglot and custom cookies.
Issue Background
The client reported an issue with their multilingual WordPress website using the Weglot translation plugin. Specifically:
- When users accessed the English version of the site and selected “Deutsch” (German) from the language picker, they were redirected to the German (.de) version correctly.
- However, if the user later attempted to switch back to English, they were continuously redirected back to the German site, even after choosing “English.”
- Clearing browser cookies and cache temporarily fixed the issue.
This persistent redirection loop was affecting user experience and regional site navigation.
Diagnosis
Our investigation revealed two root causes contributing to the forced redirection behavior:
- Weglot Auto-Redirection Settings: The Weglot plugin was configured to automatically redirect users based on browser language settings. This setting, when combined with cached cookies, could potentially cause redirection loops.
- Custom Code Snippet Using Region-Based Cookies: A custom snippet was found in the site’s Code Snippets plugin. This snippet set cookies based on referrer data and redirected users according to those cookies. Even after disabling Weglot’s auto-redirection, this custom snippet continued forcing redirection, overriding the user’s manual language selection.
Additionally, during troubleshooting, a login loop issue was discovered on the German site’s WordPress admin dashboard, further complicating access.
Resolution Steps
- Reviewed & Disabled Conflicting Settings: Weglot’s auto-redirection based on browser language was disabled. The problematic custom code snippet managing region-based cookies was disabled.
- Testing & Temporary Resolution: Disabling these settings initially appeared to fix the issue; however, caching was suspected to still be affecting the behavior.
- Detailed Code Review: Upon deeper inspection, the custom snippet was found to contain JavaScript that detected the referrer, added cookies, and redirected users based on those cookies. This script was aggressively forcing redirects, even when the user tried to manually change their language preference.
- Final Fix: We commented out the portion of the snippet responsible for setting cookies and redirecting users. All caches were cleared, and the site was tested extensively, both logged in and in incognito mode. The redirection loop was resolved, and language selection behavior returned to normal.
Final Outcome
The client confirmed that the issue was fully resolved. Users can now switch freely between English and German versions of the site without being redirected incorrectly.
Key Technical Takeaways
- Language Auto-Redirects & Cookies: Combining Weglot’s auto-redirection with custom cookie-based redirection scripts can create conflicts and loops.
- Cache Impact: Even after disabling problematic code, browser and server caching can cause lingering issues.
- Custom Snippets Review: Always audit custom code snippets that may be present when troubleshooting WordPress functionality.
- Testing: Conduct thorough testing in multiple scenarios (logged in, logged out, incognito) after changes.
Experiencing redirect loops or multilingual issues on your WordPress site?
Freshy can help you troubleshoot, optimize, and resolve plugin and redirection conflicts.
Contact Freshy for WordPress support