Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
how it's possibile to create a dynamic hreflang in a multilingual website?
I have this structure:
The name of the nodes are in the language of the root, because the name of the node generates the url. So it's important to mantain the language of the root node.
How can I link with the hreflang tag the same page in the other languages?
FYI: You can change the URL of the node with a nifty built-in property of Umbraco called umbracoUrlName. If that field is set, it will use it instead of auto-generating one using the name of the node.
(Legacy, but it still applies)
Thank you so much!
I recently had to do this for v6 site i used https://our.umbraco.org/projects/backoffice-extensions/viziozrelationships/ you could as done in this package use relationships api. If you have created your other language sites via copying a language node and have checked relate on copy checkbox then in the relations table there will be a relationship and you can use the relations service to get related language instances of a page.
Thank you so much Ismail, but I use Umbraco v7.0 :)
Mr @Craig100 has made a great macro implementation here:
Hi and thank you for your reply.
I tried the macro but it doesn't work for me.
All the pages has only one lang tag, set as "x-default", also if I'd copied the pages from the same node...
If you have not setup relationships on your language variant nodes (i.e. you need to apply this to an existing multi-lingual website), relationships are not going to be the answer without some heavy content changes in the back-office.
I managed to get to a solution for one of my sites with a Linq query. It does make a few assumptions. The first is that there is one root node, above the site root language nodes. The second is that alternative pages all have the same Node Name. The exception to this would be the root language node, which could be named UK, US, FR etc. Another assumption is that the general tree structure across different language sites is the same (levels).
Here is the code, which is placed in the master template of the website. Hopefully someone else will find this useful.
var currentNode = Model.Content;
var rootNode = currentNode.AncestorOrSelf("docTypeAliasOfSiteRootNode");
var alternatePages = rootNode.Descendants()
.Where(x => x.DocumentTypeAlias == currentNode.DocumentTypeAlias &&
x.Level == currentNode.Level &&
x.Parent.DocumentTypeAlias == currentNode.Parent.DocumentTypeAlias &&
(x.Parent.Name == currentNode.Parent.Name || x.Parent.DocumentTypeAlias == "docTypeOfRootLanguageNode") &&
(x.Name == currentNode.Name || x.DocumentTypeAlias == "docTypeOfRootLanguageNode")).ToList();
Then to populate the meta tags we would need something like this:
@if (currentNode == rootNode)
<link rel="alternate" href="@currentNode.UrlAbsolute()" hreflang="x-default" />
foreach (var languageNode in rootNode.Children().Where(x => x.DocumentTypeAlias == "docTypeOfRootLanguageNode"))
<link rel="alternate" href="@languageNode.UrlAbsolute()" hreflang="@languageNode.GetCulture().ToString()" />
@if (alternatePages != null && alternatePages.Any())
if (alternatePages.Count == 1)
<link rel="alternate" href="@alternatePages.First().UrlAbsolute()" hreflang="x-default" />
foreach (var altPage in alternatePages)
<link rel="alternate" href="@altPage.UrlAbsolute()" hreflang="@altPage.GetCulture().ToString()" />
I hope someone else finds some use of this. I'm also open to suggestions on improving this code.
Thank you for sharing your solution, Nathan.
Unfortunately I can't use your code 'cause I have a root node for each language and I have different node names, because the node name create the url, and for SEO is better if the url is in the language of the page...
Thank you the same :)
The URL Name is a good point, however if you don't speak the language of the site you are supporting, it is very hard to navigate the content tree by naming the nodes in a different language. To reduce those administrative woes, you can use the property umbracoUrlName to override the URL with whatever name you want.
If you don't have a root node, you would have to modify the linq query to handle your tree setup, but the principles would be mostly the same.
Nice idea! Really useful! Thank you :)
Roberto- were you able to find a solution for this?
On my site I have two languages (French and English) and a root node for each language. My solution was to use Content Picker on my SEO tab that is on every page within my Umbraco installation. Content editor would then manually pick localized version of a page.
Then on my master template I added the following:
var ukAlternateLinkTag = "";
var frenchAlternateLinkTag = "";
if (CurrentPage.hreflang != null)
if (Culture == "fr-FR")
frenchAlternateLinkTag = "https://www.siteurl.fr" + CurrentPage.Url;
ukAlternateLinkTag = CurrentPage.hreflang.Url;
frenchAlternateLinkTag = CurrentPage.hreflang.Url;
ukAlternateLinkTag = "https://www.siteurl.co.uk" + CurrentPage.Url;
@if (!string.IsNullOrWhiteSpace(frenchAlternateLinkTag) && !string.IsNullOrWhiteSpace(ukAlternateLinkTag))
<link rel="alternate" hreflang="en-US" href="@ukAlternateLinkTag" />
<link rel="alternate" hreflang="fr-FR" href="@frenchAlternateLinkTag" />
Please note that the proper way doing this would be to use the Umbraco RelationService. However, to make this work, the content editor would need to create the language equivalent of a page by copying the page and and having "Relate to original" enabled.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted