WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. gombroo
    Member
    Posted 1 year ago #

    Hello,

    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
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    Another solution which worked fine for me I found here:
    http://www.qianqin.de/qtranslate/forum/viewtopic.php?f=3&t=2998#p11455

  4. webbeur
    Member
    Posted 1 year ago #

    promopix Your solution is the best !
    Thanks !

  5. akhilesh1010
    Member
    Posted 11 months ago #

    grate solution thanks for promopix

  6. nicozz
    Member
    Posted 10 months ago #

    Wonderful!
    Thank you promopix for sharing !! :)

  7. ondigit
    Member
    Posted 10 months 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.
    http://mysitemyway.com/support/topic/qtranslate-home-link-infocus-theme

    jQuery(document).ready(function(){
    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. Tschan
    Member
    Posted 9 months 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. Tschan
    Member
    Posted 9 months 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
    Member
    Posted 9 months 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
    Member
    Posted 9 months 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
    Member
    Posted 7 months ago #

    Thanks everyone for sharing the solutions.

Topic Closed

This topic has been closed to new replies.

About this Topic