We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50687
    • 2 Posts
    Hello,

    I made a multilingual website with Babel (2 contexts) and would like to make correct usage of the hreflang attribute, i.e. for example for a fictional website www.examplesite.de/ex1de.html there would be hreflang-attributes as follows:
    <link rel="alternate" hreflang="de" href="http://www.examplesite.de/ex1de.html/" />
    <link rel="alternate" hreflang="x-default" href="http://www.examplesite.de/ex1en.html/" />

    x-default would be English in this case, if the language should not be “de”.

    After browsing for a while, I found the following solution:

    1) In the template of the page: BabelLinks call
    [[BabelLinks? &tpl=`hreflangTemplateChunk`]]
    2) The according hreflangTemplateChunk:
    <link rel="alternate" hreflang="[[+cultureKey]]" href="[[+url]]" />

    Unfortunately, this does only work partially, because the produced entry in the <head> of the page does only relate to the other language. But there is no self-referencing of the active language version.
    Moreover, being on the DE page, the hreflang attribute is only shown as „en“, then. How is possible, to use “x-default” instead of “en”, as shown in the examples above.

    I am not that much into MODX programming, unfortunately.

    Thanks a lot!
    [ed. note: mic0001 last edited this post 11 years, 2 months ago.]
      • 50687
      • 2 Posts
      Just in case, anybody else is facing the same problem:
      I found a solution using BabelTranslation.

      Add this to the head of your site:
      <link rel="alternate" hreflang="de" href="[[~[[BabelTranslation? &contextKey=`web`]]? &scheme=`http`]]" />
      <link rel="alternate" hreflang="x-default" href="[[~[[BabelTranslation? &contextKey=`en`]]? &scheme=`http`]]" />

      The contextKeys shown here have to be adjusted to the ones you are using in your project.