
- MODX 3
- PHP 8.2
- Vue 3


The getLocalizedCanonical snippet outputs link rel="canonical" for the current language and link rel="alternate" hreflang="..." for active languages. You do not need a custom markup snippet.
It adds hreflang="x-default" when a default-language URL is found. localizator3_default_language is compared to the language key, not cultureKey. If the setting is empty, the current language URL is used.
| Name | Default | Description |
|---|---|---|
| id | current resource | Resource ID. Empty null and '' use the current resource. Empty string if there is no resource |
| tpl | empty | Chunk name or @name via pdoFetch. Placeholders: links (items with url, hreflang, is_current, language_key) and ready output. If the chunk is not found, the default markup is kept |
The snippet returns an empty string when:
localizator3_key;canonical and, with an empty setting, x-default appear only if the current key belongs to an active language with a non-empty URL.
Languages are sorted by rank, then by id. In markup, canonical belongs to the current language; x-default is output last.
The hreflang value comes from the language cultureKey, otherwise from the key. URLs are built by makeLocalizedUrl.
{'!getLocalizedCanonical' | snippet : ['id' => $_modx->resource.id]}[[!getLocalizedCanonical? &id=`[[*id]]`]]Sample output (order depends on rank):
<link rel="canonical" href="https://site.example/page.html">
<link rel="alternate" hreflang="ru" href="https://site.example/page.html">
<link rel="alternate" hreflang="en" href="https://en.site.example/page.html">
<link rel="alternate" hreflang="x-default" href="https://site.example/page.html">