Closed tibbis closed 3 hours ago
Sitemaps are not rendered at the same time as a entry's template, so that wouldn't work for this.
You could do the first part via Twig (or PHP) for the entry pages. And then for the sitemap, probably you could listen on the SitemapHelper::EVENT_INCLUDE_SITEMAP_ENTRY
event to not include that entry in the sitemap, and include it yourself via SitemapCustomTemplate::EVENT_REGISTER_SITEMAP_URLS
https://nystudio107.com/docs/seomatic/advanced.html#registersitemapurlsevent
In general, it's best to try to leverage Craft's functionality, but if you need to step outside of that, it still should be possible using the hooks above.
If not, we can look into adding a hook for you.
I assumed that and I also want to just use the build-in functions. But the main problem is that in craft site settings ut doesn't allow country codes to the language site setting. E.g English (Estonia) "en-EE" doesn't exist as a lang/region combination, so the hreflang can only be just "en" now.
May not be a problem for SEO, but is there any way to modify what seomatic look at as language/locale?
So a pretty easy way around your first problem is to ask Pixel & Tonic to add the language combinations that you need to the site settings.
SEOmatic derives everything from these site settings in terms of the locale/language. Currently there are no hooks to do otherwise.
Looks like it might be possible via extraAppLocales
: https://craftcms.com/docs/5.x/reference/config/general.html#extraapplocales
Is your feature request related to a problem? Please describe.
Let's say we have 2 sites in a site group and 2 entries connected between the sites where the hreflang is correctly added on both pages and in the sitemap. Then we add a third page one of the sites but not connected to the same entry id (as we cant do that in any way), that has a different locale country.
Or another scenario is that you want to add the country code to hreflang of these two pages (for example "English (Estonia) - en-EE" does not exist in site language settings), so you need to append "-EE" in that case, but it is not reflected in the sitemaps.
We can merge that hreflang link/tag using twig code. But it needs to be added as return link in the head on the other pages as well as to the sitemap.xml, which right now is not possible to do using twig.
As the automatic feature work very well with multi-site setup, I think the easiest would be to keep that implementation and have a way to just connect additional entries to an entry so that seomatic understands that they are related.
Describe the solution you would like
Have a function like:
{% do seomatic.link.get('alternate').addHreflang(["alternate_url.com", "fr-ch"]) %}
That will add without overriding an alternate url with locale to the current page + return link/tag on the target entry, and also add it to sitemaps hreflang.Describe alternatives you have considered