Background of the issue:
I am trying to change the language of any page on my website. The issue can be seen on this page: hidden link
Symptoms:
The language switcher button sends me to any page, and it changes randomly instead of showing the translated page.
Questions:
Why does the language switcher not direct to the translated page?
How can I fix the random page redirection issue with the language switcher?
The issue still exists after the initial checks. We would like to confirm whether there are any server-side caches in place. If so, it would be great if you could clear them, as the issue temporarily resolves for a few seconds when I purge the SG caches.
Thank you for the updates. Please allow me to make a copy of your site using the Duplicator plugin (https://wordpress.org/plugins/duplicator/) for debugging the issue on my local server. So we can troubleshoot the issue without affecting your live site.
Thank you for the permission. I made a copy of the site, but the issue remains on my local copy after the initial troubleshooting steps. So, I am consulting with our team for an expert opinion now. We will get back to you as soon as possible. Please wait.
Hello, any news? The website has a lot of traffic and it is not good to have this problem. If you can't fix the widget maybe we can find another solution, but let's do something please, my client is really upset.
We are still working on this issue. The ticket has been escalated to our second-tier team for further debugging. We will get back to you as soon as possible. Please wait.
This bug is happening becuase of a conflict with the WpResidence caching. The theme uses a custom caching method for menus by storing them in transients (temporary data that lasts for about 4 hours). When someone visits a page, the menu (including the language switcher) is saved this way, so the same menu links are shown on all other pages, even if the language links are no longer correct.
As a workaround, we have used the following code to clear these transients on every page load, so the menu updates correctly each time and shows the right language links. Our compatibility team is still reviewing it for a permanent solution.
/**
* Zap every WP Residence menu transient on each page load.
* The target string is unique enough that a single LIKE works.
*/
function cleanup_wpresidence_menu_transients() {
global $wpdb;
$like = '%' . $wpdb->esc_like( 'wpestate_wpresidence_primary_menu_complete' ) . '%';
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE %s",
$like
)
);
}
add_action( 'init', 'cleanup_wpresidence_menu_transients' );
So, please add this code in the functions.php file of the theme (at the bottom of the file, like the attached image) after a full site backup (mandatory). Then, clear all types of caches and make sure the bug exists or not.