[qTranslate] HOME menu link resets selected language back to defalut (12 posts)

  1. gombroo
    Posted 3 years ago #


    I use qTranslate plugin and WP anniversary theme.

    My default language is Polish. The second one is English.
    When I'm on English version i.e. http://www.msabu.linuxpl.info/en/biografia/ and click on NEWS (HOME) menu link, my site switches back to default language.

    I saw several answers on qTranslate forum but with no PHP knowledge I can't say which one is appriopriate.

    Thanks in advance!

  2. promopix
    Posted 3 years ago #

    I had the same problem and I just found out a way it worked for me. I am using a child theme of TwentyTen and in de wp-nav menu the home link menu item (it is a post home so no page!) switched back to the default language.
    I found it here:link
    Put it in your childtheme functions.php

    // Fix for qTranslate plugin and "Home" menu link reverting back to default language
    if (function_exists('qtrans_convertURL')) {
    function qtrans_in_nav_el($output, $item, $depth, $args) {
    $attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
    $attributes .=!empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
    $attributes .=!empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
    // Integration with qTranslate Plugin
    $attributes .=!empty($item->url) ? ' href="' . esc_attr( qtrans_convertURL($item->url) ) . '"' : '';
    $output = $args->before;
    $output .= '<a' . $attributes . '>';
    $output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
    $output .= '</a>';
    $output .= $args->after;
    return $output;
    add_filter('walker_nav_menu_start_el', 'qtrans_in_nav_el', 10, 4);
  3. gombroo
    Posted 3 years ago #

    Another solution which worked fine for me I found here:

  4. webbeur
    Posted 3 years ago #

    promopix Your solution is the best !
    Thanks !

  5. akhilesh1010
    Posted 2 years ago #

    grate solution thanks for promopix

  6. nicozz
    Posted 2 years ago #

    Thank you promopix for sharing !! :)

  7. ondigit
    Posted 2 years ago #

    For some reason I am not able to use this work around, so I used javascript to fix the menu which I found here.

    var lang = jQuery("html").attr("lang");
    if ( lang == "en-US") {
    var href = jQuery("#menu-item-402").find("a").attr("href");
    jQuery("#menu-item-402").find("a").attr("href", href + "/en");

    Hope this help somebody in future.

  8. Andy Tschiersch
    Posted 2 years ago #

    in my opinion the best work arround (works with banner-link and home-nav-link):

    add this code to your functions.php

    function qtrans_convertHomeURL($url, $what) {
        if($what=='/') return qtrans_convertURL($url);
        return $url;
    add_filter('home_url', 'qtrans_convertHomeURL', 10, 2);

    i found this solution here

  9. Andy Tschiersch
    Posted 2 years ago #

    i just found out that the additional plugin "qTranslate slug" fixed this problem allready. if you also want to translate url slugs of pages und posts, you want this plugin anyway.

  10. dmarcelino
    Posted 2 years ago #

    Tschan, the code you suggested worked perfectly for me!

    Also tried qTranslate slug but found this awkward bug.

    Thank you very much!

  11. nataliette
    Posted 2 years ago #

    Hi guys,

    I am having the same problem but it is the other menu items that reverts back to default language instead of Home. Any help, or can Tschan modify the code such that it works for my other links generated from the WordPress Menu?

    Thanks in advance.

  12. sofitamusic
    Posted 2 years ago #

    Thanks everyone for sharing the solutions.

Topic Closed

This topic has been closed to new replies.

About this Topic