Prejsť na hlavný obsah
← 📄 HTML & the platform·Modul A6 · Lekcia 9
ÚlohaAdd hreflang link tags for a 4-language page: en (/post), uk (/uk/post), ru (/ru/post), fr (/fr/post), plus x-default (/post). All absolute URLs starting with https://example.com.

hreflang: 18 jazykov, jedna hierarchia URL

100 XP8 min
Teória

When you have translated pages

Tell Google "here are sibling versions of this page in other languages, route the user to the right one":

<link rel="alternate" hreflang="en" href="https://example.com/post" />
<link rel="alternate" hreflang="uk" href="https://example.com/uk/post" />
<link rel="alternate" hreflang="ru" href="https://example.com/ru/post" />
<link rel="alternate" hreflang="x-default" href="https://example.com/post" />

Rules

  • Every translated page links to ALL siblings (including itself). If you have 18 langs, you have 19 link tags (18 siblings + 1 x-default) on EVERY page.
  • hreflang values are BCP 47: en, uk, en-US, pt-BR, zh-Hans, x-default.
  • `x-default` = the fallback when the user's language doesn't match any explicit hreflang. Usually points to your English URL.
  • Bidirectional confirmation. The UK page must link back to the EN page. If the link is one-way, Google ignores both.

Why it matters

Without hreflang, Google indexes both /post and /uk/post as separate competing pages. They cannibalize each other's rankings. With hreflang, Google knows they're the same content for different audiences — keeps both indexed, shows the right one based on user locale.

Sitemap alternative

For sites with many translations, listing hreflang in the XML sitemap (one entry per URL with embedded alternates) is more maintainable than emitting 19 link tags per page.

CodeMentor uses both

Our buildHreflangLanguages() helper on every page emits the 18 link tags, AND the sitemap includes hreflang for each URL. Belt + suspenders. Google reads either.

🔒

Zaregistruj sa a začni programovať

Teória je otvorená pre každého. Editor, živý náhľad a kontrola sa odomknú so 7-dňovou bezplatnou skúškou — karta potrebná, zruš kedykoľvek.

Registrácia — bezplatná skúška →

Prvých 10 lekcií v každej trase je zdarma. Karta nie je potrebná.

← PredchádzajúcaĎalšia lekcia →

Jeden tip k Pythonu alebo webu denne — e-mailom

Krátke, ručne písané, žiadny spam. Odhlásiť jedným klikom.