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
Thank you!!
I’ve been searching a fix for this bug for a few hours now.
Works great, once again, thanks!
Pingback: QTranslate, Come risolvere errore “Rel Alternate” | SEO | Froggybit Blog | SEO, Web Marketing and Development
Hi there,
i think the search bug is more complex to fix… but for the alternate language paths i just opened an issue with your solution here:
https://github.com/not-only-code/qtranslate-slug/issues/25
Thanks for report!
C.
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.
Hi, yes it is planned, like previous versions < 1.0
Greetings!
WOW!
after one day of search fanally found the fix!
thanks so much for sharing!
from Chile!