Home›Support›English Support›[Resolved] Cookie not changed while change the language with logged in user
[Resolved] Cookie not changed while change the language with logged in user
This thread is resolved. Here is a description of the problem and solution.
Problem: You are using WPML with Beaver Builder and have set up separate domains for different languages. However, when you switch languages in the WP Admin panel, the 'wp-wpml_current_language' cookie does not update correctly. It shows 'en' instead of 'ja', and when switching from the English domain to the Japanese domain, two cookies with values 'en' and 'ja' appear. Solution: We have identified that this issue might be related to custom code that alters WPML's default behavior. We recommend checking any custom code that might interfere with WPML's handling of cookies. Additionally, we suggest using WPML Hooks as a possible workaround for managing cookies across different domains. You can find more information on WPML Hooks here: WPML Hooks Reference. If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please 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.
Background of the issue:
I'm using WPML + Beaver Builder on my website. WPML stores the current language in a cookie named 'wp-wpml_current_language' with the language code as its value. I've created separate domains for different languages: hidden link for Japanese and hidden link for English.
Symptoms:
When I change the language to Japanese while logged into the WP Admin panel, the cookie 'wp-wpml_current_language' still shows 'en' instead of 'ja'. Additionally, when switching from the English domain to the Japanese domain, there are two cookies named 'wp-wpml_current_language' with values 'en' and 'ja'.
Questions:
Why does the 'wp-wpml_current_language' cookie not update to 'ja' when I change the language to Japanese?
Why are there two 'wp-wpml_current_language' cookies with different values when switching domains?
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Hello,
This behavior is likely due to cookie scoping rules:
- Cookies are scoped by domain.
A cookie set by hidden link cannot be read or overwritten by hidden link, and vice versa.
So, when you're on hidden link (English):
The cookie wp-wpml_current_language= en is stored for that domain.
Then, when you switch to hidden link (Japanese):
A new cookie wp-wpml_current_language= ja is set for the Japanese domain.
If you're inspecting cookies across both domains (like using browser dev tools while switching tabs), it may appear that there are two cookies with different values, but each one belongs to its respective domain, not both.
Conclusion:
The cookie doesn't "update" in the usual sense because you're crossing domains. You're actually seeing two separate cookies scoped to different domains. This is expected behavior in a multi-domain setup.
Hi
I agree with your answer. But the issue is totally different. I've created a custom filter where I get the current language using the "$current_language = apply_filters('wpml_current_language', null);" filter. I switch the language to Japanese, but still I get 'en' instead of'. That is why when I open up my blog page, I load the latest blog list with pagination, and I'm using the "$current_language = apply_filters('wpml_current_language', null);" filter to get the current language, but I am getting 'en' instead of 'ja', and also if I look into the cookie, then it is also shown as 'en' instead of 'ja', and the result is shown in the EN language blogs rather than JA language.
I am sharing the screenshot hidden link URL for your reference.
Hi
Sorry, I forgot to mention that I've created custom AJAX to load my blog posts and also show the English blog post while the user is logged in but actually I'm on the Japanese language.
Languages: English (English )Spanish (Español )German (Deutsch )
Timezone: America/Lima (GMT-05:00)
Hello,
My apologies, but if you use custom code to alter the default behavior of WPML then our support team can not take responsibility for this.
What I can offer to do is run a test on a local server try to recreate the duplicated cookie issue and then escalate to the second-tier support team.
As mentioned earlier, it might usually be expected that each cookie loads for each domain, and remains saved in the same browser session, but maybe we could offer a workaround in this case by using one of our WPML Hooks.