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:

UPDATE: Google needs now all of the languages, so i deleted the if-clause.


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) {
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

32 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

  5. Ich habe jetzt leider das Problem mit mqtranslate und WP 4.0.1. Website Standard deutsch, in anderen Sprachen funktioniert die Suche nicht und springt immer auf die Startseite.

    Unfortunately I have the same problem with mqtranslate and WP 4.0.1. Standard german website in other languages will not work searching and always jumps to the start page. Is there alredy a fix for it?

    • Hmmm… Verwendest du die aktuellste Version von mqtranslate und qtranslate slug? Diese laufen eigentlich weitestgehend problemlos unter 4.0.1, inkl. Suche…

      • Ja, aktuelle Versionen. Kann das mit https zusammenhängen? Erst nach Einbindung SSL ist mir das aufgefallen. Bin leider ziemlich ratlos. Bei einer anderen Seite hängt die Suche noch ein /en/ zu viel an (hotelroombrokers.com)

      • Kann ich mir eigentlich nicht vorstellen, dass das mit https zusammenhängen soll.

        Bzgl der hotelroombrokers-Website: kann es sein, dass dein theme eine eigene searchform.php besitzt oder eine eigene Searchform per Filter verwendet wird?

        Das mit dem doppelten /en kenne ich von der Funktion get_bloginfo(‚url‘) bzw. bloginfo(‚url‘).

        Falls also eine eigene searchform verwendet wird, ersetze da einfach das (get_)bloginfo(‚url‘) durch home_url() bzw. get_home_url(), das sollte das doppelte /en verhindern.

        Geht es auch um diese Seite bei dem anderen Problem?

        Gruß

    • ouhauerha… An der Seite sind leider einige Baustellen 😉

      Zuallererst das konkrete Problem mit der Suche:
      Bei dem Suchproblem ist es das gleiche wie bei der anderen Seite: wahrscheinlich wird die Adresse der Startseite für die Suche per get_bloginfo oder get_option ausgelesen, stattdessen solltest du besser home_url bzw. get_home_url benutzen.

      Hier noch ein paar generelle Tipps:
      Dein Theme bindet zweimal jQuery ein. Kann es sein, dass jQuery in der header.php oder in der functions.php nicht mit wp_enqueue_scripts eingebunden wird?
      (jQuery korrekt eingebunden: Zeile 36 des Quelltextes; vermutlich von irgendeinem Plugin; jQuery falsch eingebunden: Zeile 112 des Quelltextes, vermutlich vom Theme).

      Ebenso werden die Open-Graph-Tags mehrfach eingebunden, vermutlich einmal von YOAST SEO und einmal vom Plugin Social Media Buttons oder so. (Warum benutzt du eigentlich das 2-Click-Social-Media-Buttons Plugin, wenn du es dann nicht korrekt einbindest? Die Seite sendet durch den Facebook-Iframe und den Twitter-Follow-Button fröhlich Daten, ohne dass man dem zugestimmt hat…)

      Generell könnte das Theme eine Überarbeitung gebrauchen, so wie es aussieht, wurde es für eine deutlich ältere Version von WordPress geschrieben… Wie wäre es mit einem hübschen neuen Theme, das sauber auf HTML5 gebaut ist? Dann würde es auch einige der unter W3C für die Site angezeigten Fehler nicht mehr geben:

      http://validator.w3.org/check?uri=https%3A%2F%2Fwww.password-protector.de%2F&charset=%28detect+automatically%29&doctype=Inline&group=0

      Ich hoffe, diese Tipps helfen dir.

      😉

      Gruß

  6. Wenn Du mir Deine E-Mail-Adresse sendest (meine hast Du ja, weil hier angemeldet), hole ich mir gerne ein Angebot für die Überarbeitung bei Dir ein. Das Theme wurde von mir lediglich übernommen und bereitet mir eh schon Bauchschmerzen…

    • Hallo Andy,

      was wärst du denn bereit zu investieren? 😉 Entschuldige, aber ich bin im Moment extrem eingespannt und käme privat in den nächsten 2-3 Monaten nicht dazu. Alternativ kann ich dir natürlich über meinen Arbeitgeber ein Angebot zukommen lassen, bleibt nur die Frage, ob für dich ein „echter“ Auftrag an eine Agentur in Frage käme, oder ob das im Budget nicht drin ist ^^.

      Solange es nicht um riesige Geschichten geht, ist WordPress Theming aber auch ziemlich „dankbar“, wenn ich da z.B. an Typo3 denke, gruselt es mich nur. Warum versuchst du es nicht selbst einmal? Ein gutes Tutorial, wie man aus einem Blank-Theme wie _s ein „richtiges“ WordPress-Theme macht, gibt es zum Beispiel hier: http://themeshaper.com/2012/10/22/the-themeshaper-wordpress-theme-tutorial-2nd-edition/ (englisch)

      Gruß

Hinterlasse eine Antwort zu ozgursarier Antwort abbrechen