WordPress.org

Forums

Qtranslate Slug
[resolved] equivalent of qtrans_convertURL() (11 posts)

  1. Pedro Carvalho
    Member
    Plugin Author

    Posted 2 years ago #

    Hi Carlos, first, let me thank you for this awesome plugin.

    so, let me expose the problem:

    qtranslate prints out this line in header. ( in qtranslate_hooks.php)

    echo '<link hreflang="'.$language.'" href="'.qtrans_convertURL('',$language).'" rel="alternate" />'."\n";

    so, for every page, cat or post, google reports a 404 link for every language in my site.

    is there a equivalent for qtrans_convertURL() ?

    thanks a lot!

    http://wordpress.org/extend/plugins/qtranslate-slug/

  2. Carlos
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. Pedro Carvalho
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  4. Pedro Carvalho
    Member
    Plugin Author

    Posted 2 years ago #

    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";
  5. matteo.ender
    Member
    Posted 2 years ago #

    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

  6. Pedro Carvalho
    Member
    Plugin Author

    Posted 2 years ago #

    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";
  7. matteo.ender
    Member
    Posted 2 years ago #

    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

  8. Pedro Carvalho
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  9. PaRaGaS
    Member
    Posted 2 years ago #

    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?

  10. PaRaGaS
    Member
    Posted 2 years ago #

    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.

  11. Sabita Sahoo
    Member
    Posted 2 years ago #

    Thanks Carlos,
    Its working, but is there any way to get different urls depending upon the language?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Qtranslate Slug
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic