How to configure and display the `hreflang` tag in the Anqi CMS template?

Calendar 👁️ 61

As a website operator who deeply understands the operation of AnQi CMS, I am very clear that in today's global market, the importance of multilingual websites and how to use refined SEO strategies, such ashreflangTags to enhance the international visibility of the website. Anqi CMS's flexibility in multilingual support and template customization provides a solid foundation for us to achieve these goals.

Now, let's delve into how to effectively configure and display in the Anqi CMS templatehreflangTags to ensure that your multilingual site is correctly geolocated and language localized in search engines.

UnderstandinghreflangThe role of tags in multilingual sites.

hreflangTags are key elements of search engine optimization (SEO), especially for multilingual websites targeting users in different languages or regions.It indicates to the search engine the language and geographic region of a specific page, and informs the search engine that the page exists in other language or regional versions.Use correctlyhreflangLabels can avoid the issue of multilingual content being considered duplicate content, while also ensuring that users can see the version of the page that best matches their language and regional preferences when searching, thereby greatly enhancing user experience and the international SEO performance of the website.

The Anqi CMS, with its powerful 'multi-site management' and 'multi-language support' core functions, provides a natural advantage for building such websites.It allows you to create independent sites or content branches for different languages or regions and manage this content flexibly in the background.

Utilizing AnQi CMS'slanguagesLabel constructionhreflang

In the Anqi CMS template system, we have a special design for multilingual siteslanguagesThe tag can help us dynamically obtain all the multilingual site information that is configured, thereby generating the correcthreflang.

Firstly, we need to ensure that your Safe CMS backend is properly configured with multiple language sites.This usually involves adding different sites in the "multi-site management" and specifying the corresponding "default language package" and "website address" for them.These backend configurations arelanguagesThe tag is the basis for correctly obtaining data.

In the template,languagesThe usage of tags is as follows:

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

This code snippet should be placed in the public header template file of your website, for examplebase.htmlof<head>within the area. This ensures that each page includes the completehreflanginformation.

Let me explain the key part of this code:

  • {%- languages websites %}This is calling the built-in of Anqi CMS:languagesThe tag will query all the multi-language sites configured on the system backend and assign these sites' data as an array to a variable namedwebsites.
  • {%- for item in websites %}We useforLoop throughwebsitesEach site entry in the array. In each iteration, the details of the current site will be assigned toitemVariable.
  • <link rel="alternate" href="{{item.Link}}" hreflang="{{item.Language}}">: This is the corehreflangof label generation.
    • rel="alternate"This indicates an alternative version.
    • href="{{item.Link}}":item.LinkThe variable will output the absolute URL of the current language site. For example, if your English site ishttps://en.example.com/about-us.html, then it will be used as the tag of thehrefMake sure that the "Website URL" configured in the background is a complete absolute URL to avoid any parsing issues.
    • hreflang="{{item.Language}}":item.LanguageThe variable will output the language code of the current language site, for example “en” (English), “zh-CN” (Simplified Chinese, Mainland China) or “fr-CA” (French, Canada region).These language codes should strictly follow the ISO 639-1 language codes and ISO 3166-1 Alpha 2 country/region codes standard.The default language package setting in the AnQi CMS backend will directly affect this location.item.LanguageValue.

In this way, when a search engine crawls your page, it will find all links pointing to itself and all other language or regional alternative versionshreflangLabels, so that you can correctly understand the multilingual structure of your website.

x-defaultconsideration

Except to specify for each language version,hreflangLabels, we usually also set up ahreflang="x-default"The tag indicates which page should be displayed as the default or general version when no other language or regional version matches the user's settings.For example, you can point it to your main language page, or a language selector page.

Although Anqi CMS'slanguagesThe tag provides links to all language versions directly, but it does not have a specific field to mark which one isx-defaultthe version. To achievex-defaultYou may need to make additional judgments or configurations.

A common method is toforOutside or inside the loop, based on specific logic (such as judgmentitem.LanguageIs it your default language or an additional one output through custom backend settings?x-defaultLabel. For example, you can specify your main site (such as the English site) asx-default:

<link rel="alternate" href="{% system with name='BaseUrl' %}" hreflflang="x-default">

Here{% system with name='BaseUrl' %}It will output the URL of your main site (default site), you can adjust it according to your actual needs to be any URL you want to usex-defaultURL.

Summary

ConfigurationhreflangTags are an important step for multilingual websites to carry out international SEO optimization.AnQi CMS, with its flexible template engine and multi-language, multi-site management functions, provides us with a convenient implementation path.By simply puttinglanguagesTag integrated into your template header, and combined with thex-defaultThe reasonable setting, you can effectively convey the language and geographic positioning information of your website to search engines, thereby improving the visibility and user experience of your website globally.


Frequently Asked Questions (FAQ)

1. If my multilingual site is set up in a subdirectory (for exampleexample.com/en/,example.com/fr/) rather than a standalone domain or subdomainhreflangis the configuration method of the tags different?

No matter where your multilingual site is deployed in a standalone domainexample.com/example.de), subdomainen.example.com/de.example.com), or subdirectoryexample.com/en//example.com/de/) under,hreflangThe logic for generating tags is basically consistent. Anqi CMS'slanguagesThe tag while traversing different language sites,item.LinkThe variable will automatically output the complete URL of the language site, whether in subdirectory form or as a standalone domain.The key is that you have correctly configured the 'website address' for each language site in the 'Multi-site Management' section of the Anqi CMS backend.As long as the website address is filled in correctly,hreflangin the labelhrefthe attribute will automatically become the correct absolute URL.

2. I need to ensure that each page'shreflangDo the tags point to the correct alternative versions? For example, the English 'About Us' page should point to the French 'À Propos de Nous' page.How does AnQi CMS handle page-level issueshreflang?

Yes,hreflangTags are usually at the page level. Anqi CMS'slanguagesTags obtain the relative path of the current page and combine it with the 'website address' of each language site to build the completeitem.LinkThis means that if you usebase.htmlthe abovelanguagestag code, then when the user accesseshttps://en.example.com/about-us.htmlthen,item.Linkit will behttps://fr.example.com/about-us.html(Assuming the root URL and page path structure of your French site is consistent). If the page paths for different language versions are different (for example, the URL for the French page is/a-propos.html), you need to set the correct 'custom URL' in the background content management for the corresponding multilingual page, or map the page paths under different languages through more complex template logic.The '伪静态规则' and 'custom URL' features of AnQi CMS can help you flexibly manage these page paths.

3. How to add labels for my multilingual sitex-default hreflangto indicate the default or alternative page? Does AnQi CMS have built-in settings?

Of Security CMSlanguagesTags are mainly used to list all the multi-language sites configured and their language codes. It does not have a built-in feature to mark or identifyx-defaultthe version field. To addx-default hreflangLabel, you usually need to add an extra one in the templatelinkThis can be achieved by manually specifying a page URL, for example:<link rel="alternate" href="https://www.example.com/" hreflang="x-default">Herehttps://www.example.com/Should be the URL of your general or default language page. You can combine{% system with name='BaseUrl' %}tags to dynamically retrieve your main site URL and use it forx-defaultofhrefThe value. If your website logic is complex, it needs to be dynamically selected based on certain conditionsx-defaultThe page may require implementing this goal by customizing fields in the background or writing more advanced template logic.

Related articles

How to use `join` and `split` filters to handle strings and arrays in AnQi CMS template?

As an experienced CMS website operation person in Anqi, I am well aware of the importance of flexible data handling in content management and display.The AnQi CMS template engine provides a rich set of filters to help us achieve this goal, among which the `join` and `split` filters are particularly powerful in handling string and array data, allowing our content display to be more dynamic and accurate.

2025-11-06

How to use `truncatechars` and `truncatewords` in Anqi CMS template?

As a website operator who is well-versed in the operation of AnQiCMS, I deeply understand the subtleties of content presentation.How to elegantly handle the display of text content when building an engaging and user-friendly website experience.AnQi CMS, with its flexible class Django template engine, provides us with powerful content control capabilities, among which the text truncation feature is a commonly used tool for optimizing page layout and improving reading experience.

2025-11-06

What is the role of the `safe` filter in the AnQi CMS template and when should it be used?

As a professional deeply familiar with the operation of Anqing CMS, I know the importance of template security and the correct presentation of content for a website.In the Anqi CMS template system, the `safe` filter plays a key role, concerning the security and display effect of the website. ### Automatic Escaping Mechanism of AnQiCMS Template AnQiCMS template system draws on the syntax characteristics of the Django template engine, one of its core design philosophies is security.

2025-11-06

How to use the `stampToDate` tag to format timestamps in the Anqi CMS template?

In website content management, the accuracy and aesthetics of time presentation are crucial for user experience.Whether it is the publication date of the article, the update time of the product, or the submission time of the comments, a clear and consistent date format can significantly improve the readability and professionalism of the content.AnQi CMS is an efficient and flexible content management system, deeply understanding this, and provides a powerful and simple tool for template developers - the `stampToDate` tag, which is specifically used to format timestamps into various custom date and time display formats.

2025-11-06

How to implement user group management and VIP paid content settings in AnQi CMS?

How to implement user group management and VIP paid content settings in AnQi CMS?As an experienced website operator, I am well aware that fine-grained user management and flexible content monetization capabilities are crucial for the success of a website.AnQiCMS (AnQiCMS) provides strong support in this aspect, allowing website operators to build differentiated user services and effectively realize the monetization of content value through its user group management and VIP system.

2025-11-06

How to use the `dump` filter to debug variable structure in AnQi CMS template?

As a senior CMS website operation personnel in a safety enterprise, I am well aware of the importance of quickly understanding data structures in template development and content optimization for debugging and accurate content presentation.Although AnQiCMS's template engine is syntactically similar to Django's template engine, providing rich tags and filters, but upon further examination of the provided documentation, it can be found that there is no explicit list of a filter named `dump`.

2025-11-06

What are the specific steps for one-click deployment of AnQiCMS on aaPanel/Baota Panel using Docker?

As a website operator who deeply understands the operation of AnQiCMS, I am fully aware of the importance of an efficient and stable content management system for the development of a company.AnQiCMS with its high-performance architecture based on the Go language, flexible content model, and SEO-friendly design, provides an excellent solution for small and medium-sized enterprises and content operation teams.It is committed to making website deployment simple, secure operation, elegant interface, and extremely fast execution speed, effectively avoiding many potential security issues.

2025-11-06

How to determine if my Baota panel version meets the Docker deployment requirements of AnQiCMS?

All colleagues, hello.As a senior website operator, I know that when deploying and managing websites, the compatibility of the infrastructure is the key to ensuring stable operation of the system.Today, let's discuss a common question: How to determine if your Baota panel version meets the Docker deployment requirements of AnQiCMS (AnQiCMS).

2025-11-06