Tag Archives: fix

How to fix qTranslate changing languages when pressing home button

19 Mar

qTranslate is a WordPress plugin that allows you to install multiple languages for your blog. The only problem with it is that when you press the Home button, it will switch back to the default language. So, I searched for a fix for this problem, and I manage to find one that actually worked.

Problem:

qTranslate automatically changes languages when pressing Home button

Fix:

  • Locate your functions.php file in your theme directory on your FTP. If you can’t access FTP, go to Dashboard -> Appeareance -> Editor -> functions.php
  • open for edit
  • go to the end of the file, right before the last ?>
  • add the following code before ?> and press update/save

the code:

add_filter('wp_nav_menu_items','qtrans_in_nav_function');
function qtrans_in_nav_function ($nav){

$url = get_bloginfo('url');
$url_preg = preg_replace('/\//', '\/', $url);

$qtrans_url = qtrans_convertURL($url);

$nav = preg_replace('/('.$url_preg.')(\/id)/', $url, $nav);
$nav = preg_replace('/('.$url_preg.')/', $qtrans_url, $nav);

return $nav;
}

You’re done now! It should work if you refresh the page. If it’s not working, try it in a clean browser! It worked for me.