I have a wordpress-based web site which is both in French and English. In order to be able to handle the two version easily I’m using the qtranslate plugin (a great plugin by the way !).
Almost everything worked fine. The only issue I found was that if I clicked on my logo I was going to the appropriate home page but if I clicked on “Home” in the navigation menu, I was going to the home page in the default language.
I’ve setup qTranslate to have such URLs:
- xxxx.com/fr/contact/ for the French contact page.
- xxxx.com/en/contact/ for the English contact page.
- Since French is the default language on this site, xxxx.com/contact is also taking you to the French contact page.
So basically you start on the French home page, click around and keep seeing the French version of the pages. Then change the language to English, click around and keep seeing the English version of the pages. But when you click on “Home”, instead of going to xxxx.com/en/, you go to xxxx.com/fr/ which then switches you back to the French site.
After a lot of googling, code reading and trying various stuff, I finally figured out a solution:
qTranslates installs a filter for all wordpress hooks related to displaying posts/pages or navigating to make sure that you see the right page. But it looks like no filter is installed for ‘home_url’. Just adding it solved the problem.
In order to fix it, go to Plugins > Editor. Choose qTranslate. Then open the file qtranslate/qtranslate_hooks.php. Scroll down. At the end of the file, you’ll see a bunch of add_filter(…); calls. Add there the following:
Save the file and enjoy clicking on the Home menu item without having the language reset to default !