Overview of the Issue
If you are using a /%category%/%postname%/ permalink structure, when you visit the last post published, the WPML language switcher will point to the wrong URL.
For example, instead of pointing to:
https://domain.com/nl/news-nl/hello-world-nl/
It will direct you to:
https://domain.com/nl/news-en/hello-world-nl/
Workaround
This issue is fixed in WPML 4.6.4. Updating solves it on your site, so you only need this workaround if you can’t update yet.
Please, make a full backup of your site before proceeding.
- Open your theme’s functions.php file.
- Add the following snippet:PHP
add_filter('template_include', function($t){ wp_cache_flush(); return $t; }, 999);