How to implement hreflang in Magento 2
If your eCommerce site operates across multiple markets then you will need hreflang tags and you will need to ensure they are set up correctly.
If your site does not have hreflang tags set up or if they are set up incorrectly then it will result in a negative impact on your SEO and user experience. For example, individual store views for different locations may start to compete against one another in the search results (for example a US jeans page vs a UK jeans page).
This can result in lower rankings and/or a poor experience for customers that land on your website. E.g. a UK customer landing on a USA page that shows US dollars and your US stock. This would also impact negatively on your engagement and conversion metrics.
Options to Implement Hreflang
Hreflang can be implemented via several different methods in Magento 2:
- Hreflang sitemaps
- HTTP header response
- HTML code
For this example, we’re going to focus on the hreflang sitemap.
eCommerce sites are naturally much larger than normal websites, coupled with the fact the sites are built dynamically, which can easily start to cause headaches for Google. We always recommend eCommerce websites to implement hreflang in the sitemap, for the following reasons:
- Sitemaps are generated dynamically
- The sitemaps are separate from the onsite code so will never be affected by a code release or dev error
- HTML codes rely on page load which has varying experience and can cause bloat
- It’s easier to manage and spot errors in the sitemap
- There’s less of an issue with ‘non-referring’ pages that are missing a hreflang back to a referer
This is particularly important for websites over 10k URLs. It’s important to select ONLY ONE of the above implementation routes in Magento 2. If you implement 2 and they contradict each other then Google will just ignore them with no error or alert.
"For eCommerce websites, we recommend implementing hreflang in the sitemap"
How to implement Hreflang in Magento 2?
- Download & install Amasty https://amasty.com/seo-toolkit-for-magento-2.html
- Log into Magento back end
- Navigate to Content > Amaty XML Google Sitemap then click XML Google Sitemap
- Next click ‘add sitemap’
- Name the sitemap with ‘hreflang’ so you know it’s not the main sitemap or an image sitemap e.g. /sitemaps/hreflang-sitemap.xml is completely fine
- Select your main market as the store, it doesn’t matter as the 1 sitemap will generate sitewide referring tags
- On the left-hand side navigate to a product and select ‘yes’, once you do this you will get additional options including ‘add hreflang tags’ which you set to yes
- Exclude images from this sitemap
- Keep out of stock products in this sitemap to avoid referencing errors if a product is out of stock in one market but not the other
- Next move to ‘categories’ then ‘pages’ with the same set up as steps 8 and 9
- Once done, click save
- Now submit this sitemap to Google through your Google search console account here
- Add this URLs to your robots.txt. Find out how with our guide to editing the robots.txt on magento 2
Note: a sitemap has a limit of 50k, if yours exceeds this amount then Amasty will automatically create an ‘index’ URL which is just a ‘contents’ page of all of the hreflang sitemaps you’ve created. Once you have this ‘index’ you can submit that 1 URL to Google as well as the ‘children sitemaps’
Conclusion
Hreflangs are essential for any eCommerce store that wants to trade across markets and gather relevant high-quality traffic. The Amasty plugin is the best option we have found to generate these tags without having to worry about additional dev resources.