Plugin Author
Carlos
(@carlos_a_sanz)
Hello,
i omitted this function because it makes no sense, you can use wordpress official functions for current language (get_permalink, get_term_link, etc.. )
Anyway there is a function to know the current url in other language:
global $qtranslate_slug;
$english_url = $qtranslate_slug->get_current_url('en');
In next versions i will add another function to know other urls in no current language.
Hope this helped you.
C.
thanks Carlos for the quick reply.
that function was a nice little wrapper that all kinds of taxonomies and post types.
gonna try your suggestion and be right back to post the results.
works perfectly!
here’s my code to replace that line (around line 489)
global $qtranslate_slug;
$language_url = $qtranslate_slug->get_current_url($language);
echo '<link hreflang="'.$language.'" href="'.$language_url.'" rel="alternate" />'."\n";
hi pedroghandi,
unfortunately i get the same 404 when switching from one language back to the other. I’m very interested in your solution but I can’t reproduce it.
Could you tell me in which line I would have to put / replace the code you posted above? That’d be awesome.
Thanks a lot
matteo
Hi matteo
in qtranslate_hooks.php, around line 489
look for this line:
echo '<link hreflang="'.$language.'" href="'.qtrans_convertURL('',$language).'" rel="alternate" />'."\n";
and replace it with
global $qtranslate_slug;
$language_url = $qtranslate_slug->get_current_url($language);
echo '<link hreflang="'.$language.'" href="'.$language_url.'" rel="alternate" />'."\n";
thanks for the quick response
now i get one of my favorites 😉
Fatal error: Call to a member function get_current_url() on a non-object in /usr/www/users/hoteltq/wp-content/plugins/qtranslate/qtranslate_hooks.php on line 44
i found the code around line 44 (qtranslate_hooks.php has about 360 lines in the latest version 2.5.28) where i replaced it with your snippet. Maybe I need another version of qtranslate – could this do the trick?
sincerely
matteo
i’m using 2.5.30 but nevertheless, you’re right. its around 44 indeed.
hm does it look like this:
// set links to translations of current page
foreach($q_config['enabled_languages'] as $language) {
if($language != qtrans_getLanguage()) {
global $qtranslate_slug;
$language_url = $qtranslate_slug->get_current_url($language);
echo '<link hreflang="'.$language.'" href="'.$language_url.'" rel="alternate" />'."\n";
}
}
notice the global $qtranslate_slug;
part.
I would just like to point to the fact, that a simple language switcher based on a current URL query is not applicable in every situation.
Right now I’m developing a multi-language website that’s integrated with Facebook. See where I’m going with this?
I’m in need of a function that would let me output a permalink to only the base language version of a post, for use in the loop (ie. front page recent posts list), so the Facebook likes and comments don’t get separated between different language permalinks.
Any edits you’d suggest?
Also, the get_current_url solution doesn’t account for any tickets added by external referrals. So again, in this situation, all the Facebook plugins point to yet another location.
Thanks Carlos,
Its working, but is there any way to get different urls depending upon the language?