how it's possibile to create a dynamic hreflang in a multilingual website?
I have this structure:
English root
nodes in english
Italian root
nodes in italian
German root
nodes in german
French root
nodes in french
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.
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.
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.
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...
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.
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.
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.
Create a dynamic hreflang tag
Hello,
how it's possibile to create a dynamic hreflang in a multilingual website?
I have this structure:
English root
Italian root
German root
French root
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) https://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlname/
Thank you so much!
Bob,
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.
Regards
Ismail
Thank you so much Ismail, but I use Umbraco v7.0 :)
Hi
Mr @Craig100 has made a great macro implementation here: https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/76546-how-to-build-link-rel-alternate#comment-248053
Best regards Jan
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.
Then to populate the meta tags we would need something like this:
I hope someone else finds some use of this. I'm also open to suggestions on improving this code.
Cheers,
Nathan
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 :)
Hi Bob,
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.
Cheers,
Nathan
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:
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...