By default, WPML does not set the language cookie for site visitors that are not logged in. However, some themes and plugins need to run AJAX calls on the front-end, based on language information. For this purpose, you can manually enable a language cookie that supports AJAX filtering.

To enable language information for the front-end AJAX calls, go to the WPML -> Languages page and scroll down to the Language filtering for AJAX operations section. There, check the Store a language cookie to support language filtering for AJAX option.

Enabling the language cookie that supports AJAX filtering on the front-end

Enabling the language cookie that supports AJAX filtering on the front-end

Now, WPML will set a cookie using JavaScript which allows it to return the correct content for AJAX operations.

This is how this works for visitors:

  • For users that are logged-in, nothing changes and this setting is not applied. Language cookie is saved normally using PHP.
  • For users that are not logged-in, WPML checks if this setting is turned on and if so, the language cookie is set using JavaScript. This allows WPML to set the language cookie even if the site is cached.