This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is experiencing an issue where the language switcher on their website does not direct to the translated page but instead redirects randomly. This problem is due to a conflict with the WPResidence theme's caching method, which incorrectly caches the language switcher links.
Solution:
1. As a temporary fix, we recommend adding the following code to the functions.php file of your theme to clear the WPResidence menu transients on each page load, ensuring the menu updates correctly and displays the appropriate language links:
/**
* 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' );
Ensure you perform a full site backup before implementing this code. After adding the code, clear all types of caches to check if the issue persists. 2. Additionally, the WPResidence theme team has acknowledged this bug and plans to include a fix in a future theme update. Meanwhile, they suggest disabling the Theme Menu Cache as a temporary workaround. You can find instructions on how to do this here: Disable WP Residence Cache.
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 WPML Known Issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If needed, please open a new support ticket at WPML Support Forum for further assistance.
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 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.
We have received an update from the WPResidence theme team. The fix for this bug will be included in a future version of the theme. In the meantime, they have suggested a temporary workaround: disabling the Theme Menu Cache.
hidden link
--
Thanks!
Bigul
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.