Viewing 13 replies - 1 through 13 (of 13 total)
  • I’m having a similar problem! I am in the process of creating a new site (WordPress 3.7.1 with Zeefocus theme)in 4 languages. I have several pages set up, and qtranslate plugin installed, as well as qtranslate Slug. The 4 flags appear correctly at the top right of the site, and if I click on any one of them from the home page, all works fine. In other words, it switches from localhosy/mysite/en to localhost/mysite/es to localhost/myslte/fr, etc…In each case the navmenu is correctly translated, and if I navigate to any of the pages, they appear in the correct language, and the URL is also correct. For example, if I am in the Spanish option, I will get localhost/mysite/es/contacto or localhost/mysite/es/montaje, etc…However, if I try and navigate from any of these pages to the same in one of the other languages, I get a 404. In other words, if I am in localhost/mysite/es/contacto and I click on the French flag, the URL that appears is localhost/mysite/fr/contacto, which of course doesn’t exist since that language’s url is localhost/mysite/fr/contactez-nous.
    What is happening is that every time one exits a page in a certain language, it seems to keep that last language in the url (also seen on the href links for each flag).
    Does anyone have any clue about how to solve this??
    Thanks a lot for any help.
    Jonathan

    Perdona Carlos,
    No se si preferirías lo mencionado arriba, en Castellano??
    Gracias y un saludo,
    Jonathan

    Carlos, ya está solucionado!
    My fault……
    I had the original qtranslate code in the header.php file, such as this:

    <div class=”chooselang” style=”float:right;”>
    <?php echo qtrans_generateLanguageSelectCode(‘image’); ?>
    </div>

    and I needed to put your qtranslate Slug code instead, as here:

    <div class=”chooselang” style=”float:right;”>
    <?php if (function_exists(‘qts_language_menu’)) qts_language_menu(‘image’); ?>
    </div>

    So now it’s working great!
    Excellent plugin. Gracias.
    Jonathan

    Plugin Author Pedro Carvalho

    (@pedroghandi)

    Elnino, do you still need help with your issue?

    Thread Starter Elnino3838

    (@elnino3838)

    Hi Carlos,

    Yes the problem still persists.
    If you check the URL https://www.the3marketers.com/blog/category/social-media/ you still have the code
    <link hreflang="fr" href="https://www.the3marketers.com/blog/fr/category/social-media/" rel="alternate" /> in the header which gives a 404.

    Jonathan’s solution does not apply to me as I don’t see anywhere in my template the line <?php echo qtrans_generateLanguageSelectCode('image'); ?>

    Thanks for your help!

    Plugin Author Pedro Carvalho

    (@pedroghandi)

    hi @elnino3838,

    try to follow the instructions from my other post that you linked at the beginning:

    in qtranslate_hooks.php,
    Line 44:

    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";

    don’t forget that if update qtranslate this changes will be lost

    Thread Starter Elnino3838

    (@elnino3838)

    Hi Carlos,

    I’ve replaced the line. Now I got a fatal error:

    Fatal error: Call to a member function get_current_url() on a non-object in /xxx/wp-content/plugins/qtranslate/qtranslate_hooks.php on line 44

    Running Version 2.5.34.
    I’ve seen this issue addressed in another post but I didn’t understand your explanation:

    https://www.ads-software.com/support/topic/plugin-qtranslate-slug-equivalent-of-qtrans_converturl?replies=11

    Plugin Author Carlos

    (@carlos_a_sanz)

    Thread Starter Elnino3838

    (@elnino3838)

    I’ve tried updating to qtranslate-slug 1.1.7 – the same link still shows up in the source code.
    I’ve tried installing mqtranslate but I can’t activate the plugin:

    Plugin could not be activated because it triggered a fatal error.

    Fatal error: Cannot redeclare qtrans_initJS() (previously declared in /xxx/wp-content/plugins/qtranslate/qtranslate_javascript.php:22) in /xxx/blog/wp-content/plugins/mqtranslate/mqtranslate_javascript.php on line 433

    Plugin Author Pedro Carvalho

    (@pedroghandi)

    hi @elnino,

    you need to use one or the other. disable qtranslate if you want to use mqtranslate.

    Thread Starter Elnino3838

    (@elnino3838)

    Nope sorry not working. When using mqtranslate, some links are broken, switching to the alternative language doesn’t work any more … Too many issues and I don’t have time to look through all of them to test if this plugin is going to resolve the prob.
    I’ll stay with qtranslate and this buggy 404 link in the header.

    Plugin Author Pedro Carvalho

    (@pedroghandi)

    well, i just tried the hack i posted earlier but this time on mqtranslate file. it now shows the right hreflang link.

    i’ll try to come up with a solution using only this plugin.

    thanks for reporting @elnino.

    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";
      }
    }

    Hi Carlos and Pedro,

    I have the same problem that Elino explain. There are any solution? Because I try to replace the code but I get a Fatal error. So what can I do?

    Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Hreflang creates broken link 404’ is closed to new replies.