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

6 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.

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 )

Verbinde mit %s