Menu

How to set up English and Spanish pages with hreflang on an Astro site
📰

How to set up English and Spanish pages with hreflang on an Astro site

DEV Community: astro·Marc Mulvaney·7 days ago
#ey5PHbQN
#devtoastro#devto#dev#astro#language
Reading 0:00
15s threshold

A lot of bilingual small business sites put both languages in the same HTML file and hide one with CSS or a JavaScript toggle. Visitors see one language. Googlebot sees both on every URL. Google detects language from the visible text, so a half-English, half-Spanish page confuses it, and hreflang is impossible because there's only one URL.

The fix is one language per URL: English at / , Spanish at /es/ , and hreflang tags linking each pair. Everything below was tested on Astro 7.4 with @astrojs/sitemap 3.7.

1. Check whether you have the problem

Open View Source on any English page and search for a Spanish word from your copy. If it's there, or the language switcher only changes a cookie or localStorage value while the URL stays the same, you need this refactor.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.