qtranslate slug bugfixing

Some of my customers need their website to be multilingual. For these cases, i like to use the plugin qtranslate. As awesome as it is, it is lacking the support of multilingual slugs for seo-friendly permalinks.

But now i found a plugin that solves this problem: enter qtranslate slugs. It adds the much needed possibility to give e.g. the english version of a page or post a different slug than the german version.

Still, there were two problems that bugged me:

  • The alternate language versions of the page are still inserted in the header by qtranslate, not knowing about the new slug versions and by that wrong
  • The searching only works in the default language. If you try to use the search feature in a different language, you see the front page. (Maybe this is only true with certain settings. I use a static front page and the ‘directory mode’ of qtranslate -> domain.com/lang-code/

To solve this problem, i tweaked the plugin a tiny bit and added a function to it.
Carlos, if you read this, maybe you could implement these changes in the next update? Thanks ;)

Change #1:

In the function ‘filter_request’ (qtranslate-slug.php line 772) insert at the start, directly after the global vars, the following two lines:

if(isset($query['s'])){
return array('s' => $query['s']);
}

Change #2:

Add the following code at the end of the plugin file:


remove_action('wp_head','qtrans_header');
add_action('wp_head','qtranslate_slug_header_extended');
function qtranslate_slug_header_extended(){
global $qtranslate_slug;
global $q_config;
if(is_404()) return;
foreach($q_config['enabled_languages'] as $language) {
if($language != qtrans_getLanguage())
echo '<link hreflang="'.$language.'" href="'.$qtranslate_slug->get_current_url($language).'" rel="alternate" />'."\n";
}
}

I hope these changes can help someone who has the same problem as me ;)

CU, Kuchen und Kakao

About these ads

23 Gedanken zu „qtranslate slug bugfixing

  1. Pingback: QTranslate, Come risolvere errore “Rel Alternate” | SEO | Froggybit Blog | SEO, Web Marketing and Development

    • Wow, great man!

      Well, may be more complex, but it worked on the sites i was working on^^ ;)

      By the way, is there any function like “get_qtrans_slug_url_by_id($id, $lang)” planned? That would be really helpful sometimes.

  2. Hi I know it’s been some time … but I am new to wordpress and first time 2-language site + search … I must doing something wrong … putting the code in teh wrong file or place … could anyone just show me how this qtranslate-slug.php should look … ? Please take in mind my php-knowledge is weak

    • What exactly doesn’t work? I need some more info ;)

      You find the qtranslate-slug.php in the plugins folder (default: wp-content/plugins/qtranslate-slug )

      If you use the latest version of qtranslate slug, you find the function “filter_request” in line 776.
      Line 778 should be free, you can insert the stuff from “Change #1″.

      You can insert the stuff from “Change #2″ either at the end of the qtranslate-slug.php, or just somewhere in your themes functions.php.

      BUT: if you don’t understand about this at all, maybe you shouldn’t use this. Messing around with source code should be done only if you know what you’re doing ;)

      Regards,
      Kuchenundkakao

      • Hi Kuchenundkakao,
        Thank You for the solution! :o)

        At first “Change #2″ didn’t work for me too, but I modified it as follows and now is ok


        add_action('after_setup_theme', 'change_qt_header');
        function change_qt_header() {
        remove_action('wp_head', 'qtrans_header');
        add_action('wp_head', 'qtranslate_slug_header_extended');
        return;
        }
        ...

  3. Hello,

    I have a multilingual site and I have also the problem that the searching only works in the default language. Results of the search query in any language redirect me to English, by default.
    I have seen you have solved this issue by using qtranslate slug and appying some changes to the qtranslate-slug.php file.

    However, when I install qtranslate-slug, my web is not working correctly, so I cannot use it.
    Do you have a hint of how to fix this issue in qtranslate directly?

    Thank you in advance!!

    • Sorry, i got no idea about the searching in the standard qtranslate or where to find it. What exactly is “not working correctly” when you install/activate qtranslate slug? Maybe i can help here ^^ ;)

  4. Well, it breaks most of the links triggered by an action. For example, when I want to view a post I am redirected to the home page.

    Thank you anyway!!

    • First of all, you should turn on pretty permalinks in the settings->permalinks menu. Otherwise, qtranslate slug just doesn’t make sense for you. Second of all, switch to mqtranslate, as qtranslate is not updated anymore, and mqtranslate can import your settings from qtranslate. After that, maybe we can see more ^^

      Greetings
      Kuchenundkakao

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ photo

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s