How to ensure the correct setting of the `hreflang` tag in the `languages` label of the AnQiCMS multilingual site?

Calendar 👁️ 67

Today, with the deepening of globalization, many enterprises and content operators need to provide customized content for users of different languages or regions. In order to ensure that these multilingual versions can be correctly identified by search engines and displayed to target users,hreflangThe correct setting of tags is particularly important. For friends who use AnQiCMS to build multilingual websites, the system built-inlanguagesTags are a powerful tool to solve this problem.

UnderstandinghreflangThe importance of tags

Before we delve deeper into how AnQiCMS helps us set uphreflangLet's take a look back first.hreflangThe role of tags. Simply put,hreflangTags are a signal to search engines that "this page has other language or regional versions." For example, if your website has a "product introduction" page with Chinese, English, and Japanese versions, then byhreflangYou can tell Google and other search engines:

  • example.com/zh/productIs in Chinese version
  • example.com/en/productIs in English version
  • example.com/jp/productIs in Japanese version

Correct settingshreflangSeveral significant benefits:

  1. Avoid duplicate content issues:Search engines will not treat content in different language versions as duplicate content, which can affect ranking.
  2. Improve user experience:Search engines can automatically guide users to the most suitable language version of the page based on their language preferences and geographical location, reducing the bounce rate.
  3. Optimize international SEO:Make sure your content can accurately reach the target audience in different global markets.

AnQiCMS, as a system designed for multi-site management and multilingual promotion, naturally willhreflangThe implementation considerations are taken into account, and a concise and efficient solution is provided.

How AnQiCMS simplifies multilingual SEO:languagesTag debut

AnQiCMS took full consideration of multilingual content management needs from the very beginning.It supports the switching and display of multilingual content, which can help operators easily expand into international markets.In the "Multi-site Management" backend, we can configure sites in different languages, set their language packs and corresponding access addresses.These configurations are set tohreflangThe generation of tags provides basic data.

In the AnQiCMS template system,languagesThe tag is specifically used to retrieve the list of all configured multilingual sites.This tag does not accept any parameters, executing it will return an array object containing information about all language sites.We can traverse this array and dynamically generatehreflangrequiredlink.

Practice: Configuring in AnQiCMS templatehreflangTag

hreflangTags are usually placed in the HTML document's<head>Within a block. In AnQiCMS, this means you need to be in the public header file, usuallybase.htmlConfigure in a similar template file to ensure it acts on all related pages.

Let's see the specific template code example:

{%- languages websites %}
{%- for item in websites %}
<link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">
{%- endfor %}
{%- endLanguages %}

The core logic of this code is:

  1. {%- languages websites %}: Invokelanguagestag, assigning information to all multilingual sitewebsitesVariable. In itwebsitesIs an array object.
  2. {%- for item in websites %}:Traversewebsitesarrayitemfor eachitemRepresents a language site.
  3. <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">: This is generatedhreflangthe key tag.
    • rel="alternate": This is a backup version.
    • href="{{item.Link}}":item.LinkDynamically outputs the complete link address of the current page on the corresponding language site. AnQiCMS intelligently handles this part, ensuring that the link points to the correct language version page.
    • hreflang="{{item.Language}}":item.LanguageThe language code of the site will be output, for examplezh-cn(Simplified Chinese),en-usor (American English)deGerman language codes need to be correctly configured in the AnQiCMS backend language package settings.

Through the above code, AnQiCMS will automatically generate the corresponding language versions for the current pagehreflangtags. For example, if you have a Chinese pageexample.com/zh/page1and configured the English siteexample.com/en/page1, you can beexample.com/zh/page1of<head>there will be a pointerexample.com/en/page1ofhreflangtags, vice versa.

Ensurehreflangsome considerations for setting correctly

It's not enough to just add the code to the template, in order tohreflangThe label plays the most effective role, we also need to pay attention to several key points:

  1. The accuracy of the site language code: item.LanguageThe language code must comply with the ISO 639-1 standard. If regional information is needed, it should be combined with the ISO 3166-1 Alpha 2 country code (for exampleen-gbRepresents British English). Make sure to correctly select the "default language package" in the "Global Function Settings" of AnQiCMS.
  2. All language version pages must includehreflang:Each page that exists in multiple languages should include links to itself and all other language versions.hreflangTags. AnQiCMS'languagesLabels are designed for this, it will traverse all language sites.
  3. Bidirectional reference: If page A points to page B, then page B must also point to page A. This is a two-way reference that ishreflangThe cornerstone of effectiveness, ensuring that search engines can fully understand your multilingual structure.
  4. x-defaultThe use of tags (optional but recommended):Although AnQiCMS'slanguagesTags are mainly used to generate links for specific language versions, but to provide a "default" or "fallback" version, you may consider adding an extra onex-defaultThe tag tells the search engine which page to display when the user's language or region does not match any specified version.For example, you can set the URL of the main site tox-default:
    
    <link rel="alternate" href="{% system with name="BaseUrl" %}" hreflang="x-default">
    
    Here{% system with name="BaseUrl" %}Used to get the base URL of the current site.
  5. Content Consistency:Ensure that the content of different language versions is an accurate translation of the corresponding language, not machine translation or low-quality content. High-quality multilingual content ishreflangthe essence of success.
  6. Test and verification:After configuration is complete, be sure to use Google Search Console and other tools to verify, checkhreflangwhether the tags are recognized correctly and there are no errors.

By fully utilizing the multi-language support features of AnQiCMS andlanguagestag,

Related articles

How to safely embed third-party statistics or advertising JS code in AnQiCMS templates?

In website operation, we often need to rely on third-party statistical tools to analyze visitor behavior, or to generate income through advertising platforms.Embed these third-party JavaScript (JS) codes securely and efficiently into website templates is a skill that every website operator needs to master.For those using AnQiCMS, understanding its template mechanism and built-in features can help us complete this task more securely.AnQiCMS is an enterprise-level content management system developed based on the Go language, which has always paid close attention to performance and security in its initial design

2025-11-09

How to determine if the `Content` field of the document is empty using the `archiveDetail` tag and display alternative content?

How can you elegantly handle the case where the document content is empty in AnQi CMS?During the operation of the website, we often publish various types of documents, which contain important information.However, sometimes for various reasons, such as the content is still in draft stage, data is missing during import, or simply some documents are only titled without detailed text, we may encounter the situation where the `Content` field of the document is empty.If the template does not perform any processing when rendering these document detail pages, the user may see a blank page area, which not only affects user experience

2025-11-09

How to judge whether a custom field exists in the AnQiCMS template and conditionally render according to its value?

In AnQiCMS template development, flexibly displaying content is the key to improving user experience and website professionalism.Among them, judging custom fields and rendering conditions based on their values is an indispensable skill to achieve this goal.In this way, you can ensure the precise display of page content, avoid displaying empty values, or dynamically adjust the page layout and functionality based on specific data.### Understanding AnQiCMS Custom Fields and Their Retrieval Methods in Templates AnQiCMS is a powerful content management system

2025-11-09

How to skip certain items in the `for` loop of the AnQiCMS template based on specific conditions?

In AnQiCMS template development, we often need to display a series of contents, such as article lists, product lists, or navigation menus.But often, we do not want to display all the data at once, but rather hope to skip a part of it according to certain specific conditions, making the final content displayed more accurate and in line with the user's needs.AnQiCMS uses a syntax similar to the Django template engine, which provides a powerful and flexible tool for us to implement this conditional skipping.To implement `for`

2025-11-09

How to judge whether an array or string is empty in AnQiCMS template using the `length` filter?

In Anqi CMS template development, we often need to decide the display content of the page based on the existence or absence of data, for example, a list of articles. If the list is empty, we may need to display "No content" instead of a blank area.At this time, the `length` filter becomes our powerful assistant, which can help us easily judge whether arrays, strings, and other data are empty.### Getting to know the `length` filter The `length` filter is a very practical feature provided by the Anqi CMS template engine

2025-11-09

How to use the `join` filter in AnQiCMS template to handle empty arrays or arrays with a single element?

In AnQi CMS template development, the flexibility of data display is crucial.We often need to present the data list obtained from the backend in a beautiful and consistent manner on the front-end, which includes the need to concatenate the elements of an array (or list) into a string.The AnQi CMS template engine provides a powerful `join` filter, which not only handles common arrays containing multiple elements but also demonstrates its unique and practical behavior in special cases such as empty arrays or arrays containing only a single element.The `join` filter is a very practical tool in the Anqi CMS template

2025-11-09

How does the `split` filter handle empty strings or strings without the specified delimiter in AnQiCMS templates?

In AnQiCMS template development, string processing is a common requirement.Sometimes we need to split a string containing multiple values into individual items so that they can be traversed on the page for display or further processing.At this time, the `split` filter has become a powerful assistant for template developers.It can split a string into an array (or slice) based on a specified delimiter, greatly simplifying the logic of complex data display.However, some specific scenarios when using the `split` filter may confuse developers who are new to the field

2025-11-09

What is the result of repeatedly outputting an empty string in the `repeat` filter of AnQiCMS templates?

AnQiCMS's template system is renowned for its concise and efficient Django-style syntax, which allows content developers to easily build dynamic pages.In daily template development, we often use various filters to process and format data.Among them, the `repeat` filter is a very practical tool that can repeat a string according to the specified number of times.However, when using the `repeat` filter, some developers may encounter a seemingly simple but easily confusing problem: when

2025-11-09