As you may know, WPML offers the option to use different domains for different languages. It turned out that I already had the same domain name with different extensions: .com and .fr. So I decided to use that WPML feature.
After following these instructions, I had everything working fine except for one thing: the home page always redirected to the default language.
At first I thought it was something I didn’t do right but I finally found someone who had the same issue as me. I tried the provided solution but it didn’t work for me. It looks like to be a bug in WPML and they won’t admit it.
So I made my own fix! It’s not really pretty, if you have a better solution, please post it in the comments.
What I am doing is adding a filter on redirects on the home page. If the original URL is a secondary language domain, I abort the redirect by returning false.
This is what you can add in the functions.php in your child theme (just replace https://benjamindurin.com with your secondary language domain):
add_filter('redirect_canonical', 'homeUrlFilter', 10, 4); function homeUrlFilter($redirect_url, $requested_url) { if ($requested_url == 'https://benjamindurin.com') { return false; } return $redirect_url; }