Bjarne Fyrstenborg
08/25/2023, 7:29 AMhreflang
to tell search engines about alternative language versions of a page, which is simply enough with the new language setup in Umbraco and just loop Cultures
on the specific node.
https://umbraco.com/blog/seo-friendly-cms-part-2-technical-seo-features#hreflang-tags
However it is also possible to use hreflang
across different domains (eventually subdomains).
What is the best way to handle this with the old language setup in Umbraco (a site node per language).
https://developers.google.com/search/docs/specialty/international/localized-versions
The similar page in another language doesn't necessary need to exists at same level.
The simple solution is just to add a content picker to site nodes, so on "en" site the content editors can pick "da", "de", "nl" etc. versions or the page, but is there a better way to handle this?Frans de Jong
08/25/2023, 10:38 AMBjarne Fyrstenborg
08/28/2023, 6:54 AMMatt Wise
08/28/2023, 7:02 AMBjarne Fyrstenborg
08/30/2023, 8:39 AMvar altPages = Model.AlternativePages
?.Append(Model)
.ToList() ?? new();
var relatedPageIds = RelationService.GetByParentOrChildId(Model.Id)
.Where(x => x.RelationType.Alias == Constants.RelationTypes.RelatedAlternativePageAlias)
.Select(x => x.ParentId == Model.Id ? x.ChildId : x.ParentId)
.ToList();
if (relatedPageIds.HasAny())
{
var page = Umbraco.Content(relatedPageIds.FirstOrDefault());
if (page is ISeo seo)
{
altPages.Add(page);
altPages.AddRange(seo.AlternativePages ?? Enumerable.Empty<IPublishedContent>());
}
}
altPages = altPages
.DistinctBy(x => x.Id)
.ToList();
if (altPages.HasAny())
{
foreach (var altPage in altPages)
{
var culture = altPage.GetCultureFromDomains();
string url = altPage.Url(culture: culture, mode: UrlMode.Absolute);
var language = LocalizationService.GetLanguageByIsoCode(culture!);
if (!string.IsNullOrEmpty(url) && url != "#" && !string.IsNullOrEmpty(culture))
{
@:<link rel="alternate" href="@url" hreflang="@culture" />
if (language?.IsDefault == true)
{
@:<link rel="alternate" href="@url" hreflang="x-default" />
}
}
}
}
A hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by