Closed der-On closed 1 year ago
@der-On just curious - is there any benefit to the hreflang
attribute being in the sitemap links as opposed to a meta tag on the pages themselves? The meta tag is something that can be done in the theme (or perhaps through the Translate plugin as a component).
@der-On just curious - is there any benefit to the
hreflang
attribute being in the sitemap links as opposed to a meta tag on the pages themselves? The meta tag is something that can be done in the theme (or perhaps through the Translate plugin as a component).
This would require including all locale variants of a page/url in the sitemap. The current implementation does not do this, but only lists the canonical urls of pages without a language prefix. Then the browser/session decides which language to display/redirect to. Not sure about how search engines do this. Maybe they index pages by mimicing various preferred languages?
I'm no SEO expert but just read that hreflang
is a best practise for multilingual sitemaps.
Maybe I'm opening a can of worms here. I'll try to ask a SEO expert about this.
Another quick search returned this: https://developers.google.com/search/blog/2012/05/multilingual-and-multinational-site
So sitemaps should instead use alternative links:
<url>
<loc>http://www.example.com/en</loc>
<xhtml:link
rel="alternate"
hreflang="de"
href="http://www.example.com/de" />
<xhtml:link
rel="alternate"
hreflang="en"
href="http://www.example.com/en" />
</url>
<url>
<loc>http://www.example.com/de</loc>
<xhtml:link
rel="alternate"
hreflang="de"
href="http://www.example.com/de" />
<xhtml:link
rel="alternate"
hreflang="en"
href="http://www.example.com/en" />
</url>
If including this in the core of the plugin is out of scope (which I can understand) adding an event to extend the generated sitemap would be good. That way one can add extra information as required for a use case or an additional plugin could do just that (like the translate or translate extended plugin).
@der-On please see this plugin: https://github.com/mjauvin/wn-mlsitemap-plugin
Ideally the Winter.Translate plugin should be able to hook into this plugin to add the appropriate multilingual configuration automatically.
Ideally the Winter.Translate plugin should be able to hook into this plugin to add the appropriate multilingual configuration automatically.
This would require an event to be able to do so. Overriding the route completely (like done in the wn-mlsitemap-plugin) is not really a good option imho as it is not extendable. Any other plugin has to do the same and so no combinated functionality can be achieved.
Yes, there has been a few conversations about adding an event in the past, I'm still open to it, just don't have time to do it myself.
Yes, I had to create this plugin in the past because I proposed adding an event and it didn't get accepted.
Yes, I had to create this plugin in the past because I proposed adding an event and it didn't get accepted.
Then let's do it again. @mjauvin do you want to redo the PR for the event or should I try an attempt?
Go for it @der-On !
@mjauvin do you have a link to your original proposal?
@der-On see https://github.com/rainlab/sitemap-plugin/compare/wip/extensibility for a starting point.
@LukeTowers Merged current main branch into your wip and made some minor adjustments https://github.com/wintercms/wn-sitemap-plugin/pull/6 Also tested it with my use case and it worked very well.
@der-On are you able to also make a PR to the translate plugin so that it can hook into these events when present and automatically make the sitemap support the localized URLs available on the site?
@LukeTowers I can do.
For multilingual sites adding the
hreflang
attribute is required for correct SEO.I would suggest that the
locale
property of a menu item should be used for that. If not present nohreflang
attribute should be attached.Problems to solve:
Automaticly add locale versions of static pages if the translate plugin is present and has more then one active locale.
I could provide a PR for that.