At my website I have a button when pressed PHP script through ajax write session variable to change language and reload page. But when I enable caching every time is loading default language. When cache is disabled everything is OK.
How translations do big pages with caching?
At my website I have a button when pressed PHP script through ajax write session variable to change language and reload page. But when I enable caching every time is loading default language. When cache is disabled everything is OK.
How translations do big pages with caching?
Share Improve this question asked Apr 21, 2020 at 15:11 SahasrarSahasrar 263 bronze badges1 Answer
Reset to default 0If you have any kind of caching enabled on a site with Wordpress, IMHO, it's probably best to use cookies instead of session variables, because with caching enabled, the user's request for a page may not even hit the server at all — so the session var isn't even being read.
What I typically do is use cookies — both setting AND reading them on the front end via ajax. You could dynamically load the new language content that way.
––-––––-
Adding on to answer your second question. If you look at a plugin like WPML or something similar, they are actually creating duplicate content in many cases. So a site might be mydomain/en
for English and mydomain/es
for Spanish. Each endpoint is cached separately. Some cookies are probably set as well, but when you switch languages with WMPL, you are actually redirected to a different page, not the same page with different language content... if that makes sense?