Why should I use hreflang in Magento 2?

Why should I use hreflang in Magento 2?

If you have an international website with multiple languages, you need to inform Google bots about what pages have the same content but in different languages. Using the hreflang attribute for your Magento 2 will help Google to rank your site correctly and offer translation suggestions.

What is Hreflang?

Hreflang is an HTML meta element that looks like this:

<link rel="alternate" href="http://example.com/en-gb/" hreflang="en-gb"/>

and used to mark duplicate content in another language.

Benefits of Hreflang attribute

There are three main advantages of using the hreflang attribute:

1. Improve the site position on SERP 

The tag makes it easier for Google bots to understand what content is preferable for a specific language search. Thus, your site will be ranked better in different markets.

2. Avoid duplicate content

When you translate the same content to different languages and place it on different URLs, Google can recognize it as duplicated content and hide these pages from search results or rank them at lower positions. The Hreflang tag allows bots to understand the difference between pages.

3. Boost user experience

As soon as the hreflang attribute helps to show the most relevant search results, users will immediately go to the page with their native language and currency without any additional actions and redirects. This will decrease the bounce rate and improve customer satisfaction.

How to implement the hreflang attribute in Magento 2?

There are 3 ways you can set the hreflang attribute:

  1. XML Sitemap 
  2. HTTP Heading 
  3. HTML Code Header 

In this article, we will show you how to set the hreflang attribute in XML Sitemap. Why sitemap?

  • It is separated from the site code and cannot lead to errors.
  • Sitemaps don’t slow down website loading.
  • It is easy to manage for non-techy specialists.
  • A sitemap is constantly updating and includes all the new pages.

Our XML Google Sitemap extension allows you to set up general hreflang URLs settings and then enable or disable this tag for specific pages and sitemaps.

1. To configure hreflang tags, go to Stores > Configuration > Amasty extensions > XML Google Sitemap and open the Hreflang URLs section.

hreflang urls section

2. In the Hreflang URLs Scope field, chooseWebsite or Global to work with one specific website or between the websites.

3. From the Language Code dropdown, select the needed language.

4. In the Country Code field, choose for what region you created the content. 

5. In the X-default field, specify which store should be tagged as default.

6. For multi-stores, you can connect CMS pages by ID, Hreflang UUID, and Hreflang URL Key. For this, set the needed option in the Multi-Stores CMS Pages Relation field.

7. Save the changes.

When creating a new sitemap, you can add hreflang tags to your Magento 2 product, category, and CMS pages. For this, navigate to Content > SEO Toolkit > XML Google Sitemaps and click Add Sitemap:

hreflang in xml sitemap

The Magento 2 XML Google Sitemap allows you to use advanced settings for XML sitemaps and includes or exclude last modified pages, out of stock products, specific product types, add category images to the map, or remove unnecessary CMS pages. Also, you can manage your current cron tasks and see their status.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.