Localizing XML Sitemaps: How to Create Hreflang Tags
To improve your website’s reach, implement hreflang correctly via XML sitemaps. If you run multiple versions of your website for different countries, it’s important that each site follows global SEO best practices. The most important thing is to clearly tell search engines how each page is related to the other and which country it’s targeting.
The best way to make this clear is to use hreflang, which can be applied as an HTML tag or as part of your sitemap.
What is hreflang??
Hreflang is a coding convention that indicates the target country and language of a web page. The term is basically a portmanteau of "href", which means "link", and "lang", which is short for "language". Hreflang tells the browser, "This version of the web page is linked to other versions in multiple languages or countries."
The two most common ways to add hreflang to a website are by adding HTML tags to the user-visible parts of your website, or by inserting them directly into your XML sitemap.
Why is hreflang important for ecommerce businesses?
Hreflang is essential for any business that has multiple global versions. It helps search engines like Google find different language versions of your site. This can help you improve your ranking for localized searches in each country.
This is especially important in ecommerce, because your currency, shipping policies, and product settings may differ across different versions of your site. For example, a customer may find your site on Google looking for the perfect pair of sneakers, carefully read product reviews and details, and decide to buy, only to discover that the product doesn’t actually ship to their country. This is because Google prioritized the wrong version of your site.
What is a hreflang XML sitemap?
An Hreflang XML sitemap is a version of an XML sitemap that includes hreflang relationships. An XML sitemap is a file that provides search engines with easily crawlable references to all the live pages on a website.
Sitemaps help crawlers avoid missing all the pages on your website. For example, the first page reference in Shopify.com's sitemap looks like this:
<url>
<loc>https://www.shopify.com/</loc>
<lastmod>2023-09-23</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
Hreflang XML sitemaps list each live page on a website and an alternate global version of that page.
For example, if Shopify uses an XML sitemap to reference English, French, and Australian versions, the first page reference might look like this:
<url>
<loc>https://www.shopify.com/</loc>
<xhtml:link
rel="alternate"
hreflang="en-ca"
href="https://www.shopify.com/ca"/>
<xhtml:link
rel="alternate"
hreflang="fr-ca"
href="https://www.shopify.com/ca-fr"/>
<xhtml:link
rel="alternate"
hreflang="en-au"
href="https://www.shopify.com/au"/>
<lastmod>2023-09-23</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
Each page version is referenced via the <xhtml:link>
tag, which contains a URL and an hreflang that indicates the language (the first two letters) and the country (the last two letters). For example, "en-au"
indicates that the language is English and the country is Australia. Note that the language always comes before the country in hreflang.
Benefits of using hreflang XML sitemaps
Properly implemented hreflang has several advantages:
Improved user experience
Hreflang helps search engines show the correct version of a page, preventing users from being confused by incorrect currency, language, or shipping policy.
Improved search engine rankings
By showing search engines that you have a version of your site tailored to local markets, you demonstrate greater local relevance than competitors who only have a single global version. This increased relevance can lead to improved rankings.
Reduce exposure risk
If a search engine determines that two pages are very similar without additional tags like hreflang, it must decide which version is the “real” or original page. Search engines will de-prioritize perceived duplicate pages, which can result in the global version of your site ranking lower.
How do I create an hreflang sitemap?
A sitemap is a specially formatted text file, usually an .xml file, and is usually hosted at `yourdomain.com/sitemap.xml`. Sometimes it includes subsitemaps. An hreflang sitemap can be created in less than a day. Here's how:
1. Check if there is an auto-generated sitemap
Sitemaps are usually generated automatically and updated regularly to reflect changes to your pages. Shopify automatically generates sitemaps for all stores and updates them weekly, but they do not include hreflang tags.
If you have an auto-generated sitemap, you’ll need to check your CMS, app, or plugin’s settings to see if it has a way to automatically insert hreflang tags. If it has this capability, it’s your best option. Be careful, though, because Shopify doesn’t currently allow editing of sitemaps.
If you are unable to edit the auto-generated sitemap or do not have a sitemap, you can create a manual hreflang sitemap to use alongside the auto-generated sitemap.
2. Start with a sitemap template
Using a template can help ensure that your sitemap follows formatting conventions. Digital Darts provides an accessible hreflang sitemap template.
3. Add all pages to your site
Include all pages that Google and other search engines will crawl. You can exclude pages that do not need to be crawled. Include only canonical URLs (official versions).
4. Add all global versions of the page
This is where local SEO comes into play. If you have adapted pages on your original website to suit local languages and cultural differences, you can add those pages at this stage. If your pages don’t have a global version, you can leave them blank.
5. Export your sitemap and upload it to your website
Copy and save the final version of your sitemap as an XML file using a text editor (such as Microsoft Visual Code ). Then upload this file to your website. In Shopify, you can do this in the Files section of your Admin.
Sitemaps are typically uploaded to the root domain, named sitemap
, and can be found on your website at website.com/sitemap.xml
. However, this is only a standard practice and is not required.
6. Submit your sitemap to Google Search Console
Submitting a sitemap to Google Search Console lets Google know about your new file and helps speed up crawling. It also lets Google check for errors in your file. You can also submit a second sitemap alongside your existing sitemap.
Best practices for creating hreflang sitemaps
There are several ways to maximize the benefits of hreflang sitemaps:
Update regularly
Update your sitemap regularly as you add new pages to your site. A complete sitemap should include all URLs (or all pages) on your site.
Check for errors
Google Search Console displays unreadable pages in your sitemap report. These errors are usually due to typos or outdated pages, so you should fix them immediately.
Setting a clear x-default
All hreflang sets must include a default version for non-local searches, defined by the “x-default” tag. The default page is usually the .com version of the site. Be sure to include this page.
Hreflang sitemap FAQ
What is the difference between hreflang tags in HTML and XML sitemaps?
Both HTML and XML sitemaps can contain hreflang tags. Search engines don't care which method you use. The main difference is how easy it is for the website owner to maintain, which depends on the capabilities of your CMS.
Are similar languages available for other countries?
Yes, the hreflang tag has a syntax that includes both language and region. For example, the hreflang tag can differentiate between English versions in the United States, Canada, and Australia.
How often should hreflang annotations be updated?
You'll need to update your hreflang comments whenever you add or remove pages to your site.
What are some common hreflang mistakes?
The most common hreflang mistake is applying hreflang only to the homepage and forgetting to include the default option (“x-default”).
What should I do if I have problems implementing hreflang?
Most hreflang issues can be fixed quickly. After updating the hreflang in your sitemap (or HTML), submit it to Google Search Console and check back after 24-48 hours to see if it is being read correctly.