How does AnQi CMS support displaying multilingual switch links and hreflang tags in the front-end template?

Calendar 👁️ 77

Today, with the increasing trend of globalization, many websites need to provide services to users from different countries and regions.This means that the website not only needs to support content display in multiple languages, but also ensure that search engines can correctly identify these different language versions, thereby enhancing the visibility in the international market.AnQiCMS as a practical content management system provides strong and flexible support in this regard.

AnQiCMS multilingual capability overview

AnQiCMS was designed with multilingual requirements in mind, making multilingual support one of its core features.This means that in the AnQiCMS backend, you can conveniently manage content of different language versions of the site, and the system itself is equipped with the ability to handle multilingual content.How does the website's frontend template display these language switch options and how to utilizehreflangLabel optimization for SEO, laying a solid foundation.

Implement multilingual switch link

To provide users with intuitive language switching options in the website front-end template, AnQiCMS provides a very convenient template tag——languages. This tag helps us to get all the multilingual site information that has been configured, and then we can iterate through this information in the template to generate the corresponding language switch links for users.

UselanguagesThe label is very direct. You can place the following code at any location on the website, such as the header, footer, or sidebar.

{%- languages websites %}
{%- if websites %}
<nav class="language-switcher">
    <ul>
    {%- for item in websites %}
        <li>
            <a href="{{item.Link}}" hreflang="{{item.Language}}" title="{{item.LanguageName}}">
                {%- if item.LanguageIcon %} {# 优先显示配置的语言图标 #}
                <img src="{{item.LanguageIcon}}" alt="{{item.LanguageName}} Flag" width="20" height="15" />
                {%- elif item.LanguageEmoji %} {# 否则显示语言Emoji #}
                {{item.LanguageEmoji}}
                {% endif %}
                {{item.LanguageName}} {# 显示语言名称 #}
            </a>
        </li>
    {%- endfor %}
    </ul>
</nav>
{%- endif %}
{%- endLanguages %}

In this code block:

  • {% languages websites %}Assign all data from multilingual sites towebsitesVariable.
  • We use{% for item in websites %}Loop through each language site.
  • item.LinkThis provides a link to the website of the current language version.
  • item.LanguageNameIt is the display name of the language (e.g., Simplified Chinese, English).
  • item.LanguageIconanditem.LanguageEmojiYou are allowed to display national flag icons or Emoji symbols to guide users more intuitively. You can choose one or both according to your actual needs.
  • hreflang="{{item.Language}}"This is also added in advance to the switch link, although its main function is in the header, but adding it here can ensure that the correct language attribute is always present when switching languages.

Through such settings, users can easily click to select their preferred language version, enhancing the website user experience.

Integrating hreflang tags to improve SEO

hreflangTags are crucial for multilingual website SEO.It tells the search engine which language or region the specific page is targeted at, thus avoiding the penalty for duplicate content and ensuring that the correct language version of the page is displayed to the corresponding users.

In AnQiCMS, you can make use of it againlanguagesTags, in the website's<head>Area automatically generates these key oneshreflangTags. This helps search engines understand the structure of your website and distribute your content better.

Open your basic template file (usually)base.htmlor a similar file), and then<head>Enter the code inside the tag:

<head>
    {# ... 其他meta标签和link标签 ... #}

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

    {# ... 其他meta标签和link标签 ... #}
</head>

This code will dynamically generate all language versions on each page loadlink rel="alternate"Tags, where:

  • href="{{item.Link}}"Points to the page URL of the language version.
  • hreflang="{{item.Language}}"Specifies the language targeted by the page (for examplezh-CN/en-US)

This allows search engines to accurately understand the relationship between each page and its corresponding language version when crawling and indexing your website, thereby effectively enhancing the SEO performance of multilingual content.

Template development precautions

When developing multilingual templates in AnQiCMS, there are still some details that we should pay attention to:

  1. Configure multilingual sitesFirst, you need to add and configure your various language version sites in the AnQiCMS backend "Multi-site Management" or "Global Settings".Each language site usually corresponds to an independent domain or subdomain, and sets the default language package. This islanguagesThe premise that tags can obtain information.

  2. Translation of static text.: Besides the content itself, the template may also contain some static text, such as navigation menu items, button text, footer information, etc. AnQiCMS providestrThe translate tag is used to process the translation of these static texts. You need to create alocalesfolders and create corresponding language files for each.ymlfile to store the translation content, for example:

    ./locales
    ├── en-us
    │   └── default.yml
    └── zh-cn
        └── default.yml
    

    Inzh-cn/default.ymlIn:

    "your_location": "您的位置"
    "home": "首页"
    

    and then use it in the template{% tr "your_location" %}The system will automatically load the corresponding translation based on the current site language.

  3. Language icon and Emoji selection:item.LanguageIconanditem.LanguageEmojiFlexible options are provided to display language identification. You can upload custom national flag icons or directly use system-supported Emoji symbols to adapt to different design styles.Ensure that the icon path you upload is correct and accessible.

By following these steps, AnQiCMS can help you easily build and manage a website with excellent multilingual support and good international SEO performance.

Common questions

How to add a new language version in AnQiCMS backend?You can find the "Default Language Package" option in the "Global Settings" of AnQiCMS backend, and create a new site in "Multi-Site Management" to specify the corresponding language package and domain, thereby realizing multi-language site management.

2. Why did I add a language switch link but it didn't switch to the corresponding language page when clicked?This is usually because you have not properly configured the domain names or links for each language version of the website.Make sure that each language site is configured with the correct "website address" and that these addresses are accessible in the "Multi-site Management" section of the AnQiCMS backend.Also, make sure your Nginx or Apache reverse proxy configuration is correctly mapping different domains/path to the corresponding language service of AnQiCMS.

3.hreflangWill the tag automatically generate all language versions of the page? hreflangThe tag itself just tells the search engine which language versions are available, it does not automatically generate the content for these language versions. You need to create and publish corresponding language versions of your content (such as articles, products, pages) in the AnQiCMS backend first, ensuring that eachhreflangThe URL pointed to is a real page that contains the corresponding language content.

Related articles

How to use the 'Remove logical tag line occupation' feature to clean up extra blank lines rendered by the template?

When using AnQi CMS to manage a website, we all hope that the page presented to the visitor is both beautiful and efficient.The page loading speed and the neatness of the source code not only affect the user experience, but also have a subtle but important impact on search engine optimization (SEO).You may have encountered such a situation in the process of template development: although the template code looks neat, there are always some unwanted blank lines in the rendered HTML source code.

2025-11-09

How to define and assign variables in a template to temporarily control the display logic of content?

In AnQi CMS template development, flexibly defining and assigning variables is the key to dynamic display of website content and personalized layout.By cleverly using variables, we can temporarily adjust the presentation of content, making the template not only able to carry basic data display but also able to present a rich and varied display logic according to specific conditions.This article will deeply explore how to define and assign variables in AnQiCMS templates, as well as their actual application in controlling the display logic of content.### The Foundation of Template Variables

2025-11-09

What methods does AnQiCMS provide for template developers to debug variable output and structure type?

When developing templates in Anqi CMS, understanding and debugging variable output and data structure types is the key to improving efficiency.Although the AnQiCMS template engine (similar to Django or Blade syntax) is intuitive and easy to use, mastering some debugging techniques can make you twice as effective when encountering problems.We usually understand the variables and data structures in the template through the following ways. ### 1.

2025-11-09

How do user group management and VIP systems affect the access permissions and display of specific content?

How to allow different users to see different content on a website, even charging for some high-value content, is the key to enhancing the value of the website and achieving monetization.AnQiCMS provides powerful and flexible features in user group management and VIP system, helping us achieve refined content distribution and differentiated display. ### Understanding the Core Value of User Groups and VIP Systems In Anqi CMS, user group management is the foundation for building personalized content experiences.

2025-11-09

How to conditionally display elements in a template based on whether the content contains specific keywords?

In website operation, we often hope that the content can be presented more intelligently to visitors.For example, if a technical article mentions a specific product, we may want to automatically display the product's recommendation information at the top or side of the article;If the product description contains the phrase 'Limited Edition', we would like to add an eye-catching 'Limited' badge next to the product image.This ability to conditionally display elements based on whether the content contains specific keywords can greatly enhance the user experience and operational efficiency of the website.AnQiCMS as an efficient and flexible content management system

2025-11-09

How to accurately截取string or HTML content and add an ellipsis to adapt to layout requirements?

In website content operation, we often encounter such needs: In order to keep the page layout neat and the reading experience smooth, it is necessary to truncate the long text (whether it is plain text or content containing HTML tags) and add an ellipsis at the end.AnQiCMS provides very practical template filters that can help us accurately complete this task while ensuring that the content display is both beautiful and does not destroy the HTML structure.### Understanding the extraction requirements and the solution of AnQiCMS Imagine, in an article list

2025-11-09

Does AnQiCMS support automatically appending a thumbnail parameter to the image address for display?

In website content operation, images are undoubtedly an important element to attract visitors, and the loading speed and display effect of images directly affect the user experience.To optimize website performance, it is particularly important to use thumbnails reasonably.Many website systems generate or call different-sized images by appending parameters to the image address.How does AnQi CMS handle this aspect?Does it support automatically appending a thumbnail parameter to the image URL to display?

2025-11-09

How to control the display form of the front-end link of category, document, and single page through custom URL alias?

In website operation, the display form of the front-end link (URL) is crucial for user experience, search engine optimization (SEO), and brand image.A concise, meaningful, and well-structured URL can not only help users better understand the content of the page but also improve the efficiency of search engine crawling and ranking.AnQiCMS (AnQiCMS) fully understands this need and provides a flexible custom URL alias function, allowing us to accurately control the link display of categories, documents, and single pages on the website's front end according to our needs.

2025-11-09