jDiction Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

jDiction 2.2.0 released. http://jdiction.org/downloads

Author Topic: Alternate Meta Tags  (Read 8793 times)

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Alternate Meta Tags
« on: November 05, 2014, 07:43:17 am »

Hi,

I have just launched our website using jdiction, and I have been looking into the SEO aspect of it and what multilingual brings to the game.

Sounds like the <link rel="alternate" and hreflang="" > tags play a big part in this.

Joomla core has this if you use associated menus, but as this plugin removes the need to associate menus is there an alternate way to implement these into the website?


All documentation I have found says to add something along the lines of

   <link rel="alternate" href="http://www.domain.com/us/" hreflang="en-us" />
   <link rel="alternate" href="http://www.domain.com/de/" hreflang="de" />
   <link rel="alternate" href="http://www.domain.com/es/" hreflang="es" />

which is easy enough in index.php, but is this then meant to adjust to

   <link rel="alternate" href="http://www.domain.com/us/english-name" hreflang="en-us" />
   <link rel="alternate" href="http://www.domain.com/de/german-name" hreflang="de" />
   <link rel="alternate" href="http://www.domain.com/es/spanish-name" hreflang="es" />

etc for other pages?

If so can this data be pulled from the Jdiction data on the fly in anyway? ie.

   <link rel="alternate" href="<current URL>" hreflang="<current lang tag>" />
   <link rel="alternate" href="<german equivilant link>" hreflang="<german tag>" />
   <link rel="alternate" href="<spanish equivilant link>" hreflang="<spanish tag>" />

Any advise/tips from anyone that has done this aspect of a multilingual site before would be appreciated.

Regards,
Jason
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #1 on: November 05, 2014, 10:50:21 am »

The jDiction plugin add these headers automatically. There is an option to disable it but by default this is on (iirc).

check the code on jdiction.org

Code: [Select]
<link href="/en/" rel="alternate" type="text/html" hreflang="en-GB" lang="en-GB" title="News" />
Logged
Joomla 3.9.x Release Lead
Vote at JED

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #2 on: November 05, 2014, 10:57:35 pm »

ok great, found the setting within the jdlanguage module... Had been looking in the plugins.

Would it be hard to modify some of them to just the 2 digit ISO code, or are these taken straight from the joomla language file?

ie: de-DE would target not just the German language, but Germany as well.
    Where as de would target anyone who speaks German.


Also, it is mentioned that you should also show this tag for the language of the page your on as well, not just the others.
Would this be possible to add manually if I knew which files to edit?


Thanks,
Jason
« Last Edit: November 06, 2014, 12:12:16 am by jstead »
Logged

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #3 on: November 11, 2014, 11:31:37 pm »

Hi Harald,

Just wondering if there was a specific file I could modify, to change how the hreflang is displayed.

Was hoping to add a little if statement for some of them that changes them from 4 digit ISO code to 2 digits.

Would this modification even be possible?

Thanks,
Jason
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #4 on: November 12, 2014, 10:25:23 am »

you can find it in the modules folder.

modules\mod_jdlanguage\mod_jdlanguage.php

Code: [Select]
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => $lang->lang_code,
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));

changing to

Code: [Select]
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => substr($lang->lang_code, 0, 2),
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));

should work.
Logged
Joomla 3.9.x Release Lead
Vote at JED

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #5 on: November 19, 2014, 07:11:43 am »

Thanks Harald,

Worked a trick!

I have tried to get tricky and have it display the 2 digit code for any unified languages, but display the 4 digit code where I have 2 variations (en-US/en-GB and fr-FR/fr-CA)

The below code changed every link dependant on if FR-CA/en-US was selected, not just the loop entry for a single line (FR/US showed 4 digit codes for ALL <link> elements while the other languages showed 2 digit)

Code: [Select]
} else {
  $tag = $current->getTag();
  $lang->active = false;
  if ($tag == 'fr-CA' || $tag == 'en-US') {
    if (($lang->menutitle != '') && ($params->get('alternatetag'))) {
    $doc->addHeadLink($lang->link, 'alternate', 'rel', array(
      'type' => 'text/html',
      'hreflang' => $lang->lang_code,
      'lang' => $lang->lang_code,
      'title' => $lang->menutitle
    ));
    }
} else {
if (($lang->menutitle != '') && ($params->get('alternatetag'))) {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => substr($lang->lang_code, 0, 2),
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
}
}
}

Where could I move the IF statement to have it apply to the loop through each language WITHIN a single page.
(so only US FR are 4 digit)
Code: [Select]
<link href="/us/" rel="alternate" type="text/html" hreflang="en-US" lang="en-US" title="Home" />
  <link href="/de/" rel="alternate" type="text/html" hreflang="de" lang="de-DE" title="Startseite" />
  <link href="/fr/" rel="alternate" type="text/html" hreflang="fr" lang="fr-FR" title="Accueil" />
  <link href="/ca/" rel="alternate" type="text/html" hreflang="fr-FR" lang="fr-CA" title="Accueil" />
  <link href="/it/" rel="alternate" type="text/html" hreflang="it" lang="it-IT" title="Pagina iniziale" />
  <link href="/es/" rel="alternate" type="text/html" hreflang="es" lang="es-ES" title="Inicio" />
  <link href="/cn/" rel="alternate" type="text/html" hreflang="zh" lang="zh-CN" title="起始界面" />

Thanks,
Jason
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #6 on: November 19, 2014, 09:59:29 am »

I still don't think that it makes any difference, but for this to work the concept have to be changed a little bit.

You have to make 2 loops, to check if there is any language 2 times like fr and en in you case. Then you have to set the correct hreflang and add it to the header.

Anyway I think its a calculation over head for each site expression and google will not need this.

And here the answer for your question ;-)
Code: [Select]
if (substr($lang->lang_code, 0, 2) == 'en' || substr($lang->lang_code, 0, 2) == 'fr' ) {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => $lang->lang_code,
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
} else {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => substr($lang->lang_code, 0, 2),
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
}
Logged
Joomla 3.9.x Release Lead
Vote at JED

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #7 on: November 20, 2014, 11:28:41 pm »

Thanks Harald,

Worked perfectly as usual!

From what I read, using the 4 digit code will indicate for Google to target the search results to the specific Country, whereas using the 2 digit code will target anyone who's system is setup as the language. So for the amount of countries we target, this addition awesome! Thank you again.

Just noticed, it also mentions you should include the tag for the current language you are on, as well as the other language versions. (is this what is removed in the first part of the If/else statement?)

Thanks,
Jason

Reference
https://support.google.com/webmasters/answer/189077?hl=en
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #8 on: November 21, 2014, 10:09:23 am »

You are right, I should fix this. Attached is a new version with a better handling for this case. (and a database function fix).

If you could deploy this version and give me feed back if everything works fine. Then I will release it to public.
Logged
Joomla 3.9.x Release Lead
Vote at JED

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #9 on: November 24, 2014, 07:19:59 am »

Hi Harald,

Thank you for this, will test ASAP.

We have just launched our website live, so I will need to wait until the development environment has been re-established.
Hopefully this should be ready tomorrow, will update once I have tested.

Kind Regards,
Jason
Logged

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #10 on: November 27, 2014, 01:18:40 am »

Hi Harald,

I have finally been able to test this new version, and it is correctly displays all languages (including current) and also toggles between 2 digit and 4 digit code.
Code: [Select]
  <link href="/en/" rel="alternate" type="text/html" hreflang="en-GB" lang="en-GB" title="Home" />
  <link href="/us/" rel="alternate" type="text/html" hreflang="en-US" lang="en-US" title="Home" />
  <link href="/de/" rel="alternate" type="text/html" hreflang="de" lang="de-DE" title="Startseite" />
  <link href="/fr/" rel="alternate" type="text/html" hreflang="fr-FR" lang="fr-FR" title="Accueil" />
  <link href="/ca/" rel="alternate" type="text/html" hreflang="fr-CA" lang="fr-CA" title="Accueil" />
  <link href="/it/" rel="alternate" type="text/html" hreflang="it" lang="it-IT" title="Pagina iniziale" />
  <link href="/es/" rel="alternate" type="text/html" hreflang="es" lang="es-ES" title="Inicio" />
  <link href="/ru/" rel="alternate" type="text/html" hreflang="ru" lang="ru-RU" title="Главная" />
  <link href="/cn/" rel="alternate" type="text/html" hreflang="zh" lang="zh-CN" title="起始界面" />

The only issue is now thou, is that not all duplicate languages would need to be 4 digits. You still need at least 1 entry from each language to be purely language (2 digit) and which one this is, could differ from user to user.

For instance in the above, the 2 English entries are United States and Great Britain country targeted. Where having
Code: [Select]
  <link href="/en/" rel="alternate" type="text/html" hreflang="en" lang="en-GB" title="Home" />
  <link href="/us/" rel="alternate" type="text/html" hreflang="en-US" lang="en-US" title="Home" />
would target the en-US spelling to United States, but the en-UK spelling to anyone else that has their system set to English regardless of country.


Not sure how this could be maintained outside of manually changing it like I did in the version prior to this (code I used below).
Code: [Select]
} else {
$lang->active = false;
if (($lang->menutitle != '') && ($params->get('alternatetag'))) {
if ($lang->lang_code == 'en-US' || $lang->lang_code == 'fr-CA' ) {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => $lang->lang_code,
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
} else {
$doc->addHeadLink($lang->link, 'alternate', 'rel', array(
'type' => 'text/html',
'hreflang' => substr($lang->lang_code, 0, 2),
'lang' => $lang->lang_code,
'title' => $lang->menutitle
));
}
}
}

Let me know if there is another aspect of it you would like me to test.

Kind Regards,
Jason
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #11 on: November 27, 2014, 10:07:11 am »

oh ok, then the first language should be the 2 digi version?
Logged
Joomla 3.9.x Release Lead
Vote at JED

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #12 on: November 27, 2014, 10:11:27 am »

Attached is a version that do this.
Logged
Joomla 3.9.x Release Lead
Vote at JED

jstead

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Alternate Meta Tags
« Reply #13 on: December 01, 2014, 11:35:09 pm »

Hi Harald,

Works perfectly!
This method is great, as it also gives the user control over which language is the default as its based of the "Language Manager > Content" ordering.

If I moved French Canadian above French in the Language Manager -> content ordering, it switched which got the 2 digit or 4 digit ISO, so this is perfect as different users would have different defaults.
Couldn't test what would happen if there were 3 variations of the same language, but assume anything after the first instance would get the 4 digit ISO as well.

Kind Regards,
Jason
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1661
    • View Profile
Re: Alternate Meta Tags
« Reply #14 on: December 02, 2014, 02:30:02 pm »

Thx the 1.3.2 is released with this change.
Logged
Joomla 3.9.x Release Lead
Vote at JED