How to use the `tdk` tag in the template to display the current page's canonical URL?

Calendar 👁️ 70

In website operation, we all hope that our content can be accurately understood and efficiently indexed by search engines.Among them, the Canonical URL (standard link) is a very important concept.It helps us solve the problem of duplicate content that may arise due to similar content or access from multiple URLs, clearly telling the search engine which is the 'main version' of the content, thus concentrating the ranking weight of the page, avoiding dispersal.

AnQi CMS as an efficient and flexible content management system, fully considers the needs of SEO optimization, built-in powerful TDK (Title, Description, Keywords) management functions, which include support for standard links. Next, let's take a look at how to properly use AnQi CMS templates.tdkLabel to display the specification link of the current page.


Understand Canonical URL and its importance

Imagine that you have an article that may have multiple links on the website for the following reasons:

  • Accessed through different category paths:/news/article-1and/featured/article-1
  • Parameterized URL:/article-1?source=baiduand/article-1?source=google
  • Even posted the same or highly similar content on your other sister sites.

These different URLs may appear as different pages to search engines, but in fact, they display the same content.If you do not give clear instructions to the search engine, it may be "confused", not knowing which version is the most important and should be ranked first, which will dilute your ranking weight.

The role of Canonical URL is like attaching an 'official specification' label to these similar content pages. By placing a<head>in the area<link rel="canonical" href="[规范链接]" />Tag, you can tell the search engine, 'Hey, although this page can be accessed from the current URL, but the main, authoritative version is here!'


Set the standard link in the Anqi CMS backend.

AnQi CMS provides detailed control in content management. When you publish or edit documents, you can set the specification link for each page individually in the background.

In detail, on the Anqi CMS backend management interface, whether you are creating new articles, products, or editing existing documents, you will find a named.The collapse area. Expand this area and you will see a field called “Standard link.

When publishing documents (or editing):

  1. Enter 'Content Management' -> 'Publish Document' (or edit an existing document).
  2. Fill in or modify the document content.
  3. Scroll the page to find “.” and click to expand.
  4. In theStandard linkEnter the authoritative URL for this page. This link should be a complete, absolute link starting withhttp://orhttps://For example:https://www.yourdomain.com/article/your-unique-slug.

When do I need to fill in this field?When a page on your website contains content that is highly repetitive of another page, and you want the search engine to index and rank only one specific version, you need to manually fill in the specification link here.If left blank, in most cases, the current URL of the page will be considered as its own canonical link.


Display the Canonical URL in the template

After setting the background content, the next step is to correctly display this specification link in the website's front-end template. Anqi CMS provides powerful template tag functions, among whichtdkThe tag is a '万能' tool we use to process page TDK information (including specification links).

tdkThe usage of the tag is very flexible, we can use itsnameSpecify the specific information to be obtained. For standard links, we usenameValue isCanonicalUrl.

Recommended template code syntax:

You should be in your template file (for exampledetail.html,index.htmlor in a public header filebash.html)的<head>Add the following code within the area:

{# 获取页面的规范链接,并将其赋值给名为 'canonical' 的变量 #}
{%- tdk canonical with name="CanonicalUrl" %}
{# 判断 'canonical' 变量是否存在且有值,如果存在,则输出规范链接标签 #}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- endif %}

Code explanation:

  • {%- tdk canonical with name="CanonicalUrl" %}This line of code will call the AnQi CMS'stdktags, throughname="CanonicalUrl"Specify the link to the current page's standard. The value obtained will be assigned to a variable namedcanonicalThe variable. It should be noted that the label before and after{%-Is to suppress extra whitespace output to make the generated HTML code neater.
  • {%- if canonical %}This is a conditional judgment, it will checkcanonicalDoes the variable have an actual value. If there is no specification link set for the current page or it is set to empty, thencanonicalthe variable will be empty and will not output<link rel="canonical" ... />Label. This is a good practice to avoid empty or unnecessary tags in HTML.
  • <link rel="canonical" href="{{canonical}}" />If:canonicalThe variable has a value, this line of code will be rendered, and the specification link should be added correctly to the page<head>area.

Where should the code be placed?

This code snippet should usually be placed in your website template.<head>Within a tag. A common location is in the public header file of your website (such aspartial/header.htmlorbash.htmlIf your template uses this structure) in it. This way, all pages inheriting or including this header file will automatically apply the standard link settings.


Summary

By using the backend management interface and flexible template tags provided by AnQi CMS, you can easily set and apply standard links to your website pages.Using the Canonical URL correctly not only helps you solve SEO problems caused by duplicate content, but also effectively concentrates page authority, thereby improving the overall performance of the website in search engines.


Frequently Asked Questions (FAQ)

1. Why is it used in the template?tdkIt is recommended to add a tag when displaying the Canonical URL?{% if canonical %}With such a conditional judgment?This is to ensure that the generated HTML code is more standardized and neat. If there is no explicit specification link set for a page in the background,{% tdk canonical with name="CanonicalUrl" %}It will return an empty value. If judgment is not added at this time and it is output directly<link rel="canonical" href="" />, it will produce an emptyhrefAttribute label. Although this usually does not cause serious errors, from the perspective of code quality and search engine parsing, it is best to only output the label when the specification link has an actual value.

2. If I do not set a 'standard link' in the background for a page,tdkWhat will the tag return? Will this page have a Canonical URL?If you have not explicitly set the 'Canonical URL' in the background,tdktags are being retrievedCanonicalUrlIt usually returns an empty value. In this case, the page front-end will not display<link rel="canonical" ... />Label. Typically, search engines will default to treating the current URL of the page as its canonical URL.Please note that if there are multiple accessible URLs or highly similar content on a page and you want to specify an authoritative version, it is essential to manually set the standard link.

3. Is the Canonical URL only applicable to article or product detail pages? Can I use it on category, tag, or single pages? tdkThe tag is a 'Universal TDK Tag', its purpose is to obtain the TDK information of the 'page'. In theory, as long as the backend of Anqi CMS provides the 'standard link' setting item for categories, tags, or single pages, you can use it{% tdk canonical with name="CanonicalUrl" %}To retrieve and display the standard links of these pages. However, according to the document description of Anqi CMS, the setting of "standard links" is mainly mentioned in the "publish document" module.For other types of pages, if the backend does not provide the setting, you need to consider according to the actual situation and SEO requirements whether you need to manually construct logic in the template to generate standard links, or confirm whether the default URL of these pages is sufficient to meet the standardization requirements.

Related articles

How to display the website's logo image on the front page?

The website logo is the core of the brand image, it not only enhances the professionalism of the website, but also deepens users' recognition of the brand.In AnQiCMS, displaying your logo image on the front page is a straightforward and flexible process, mainly involving backend settings and template code adjustments. ### Step 1: Upload and configure your Logo on the AnQiCMS backend Managing the Logo image of the website is very convenient in AnQiCMS.First, you need to upload the Logo image to the system's backend.

2025-11-07

How to enable and configure the website comment form in AnQiCMS and display custom fields?

In AnQiCMS, creating an interactive guest留言表单 form that collects feedback and can be flexibly configured with custom fields is a very practical feature.AnQiCMS provides a simple and efficient way to achieve this goal, whether it is backend settings or frontend display, it can be easily mastered. ### Enable and configure the message function on the back-end Usually, when you want website visitors to contact you or collect their feedback, a message form is the preferred choice.

2025-11-07

How to format the display of the article's publish time in the template, for example “2023 June 1st”?

When operating a website, the time an article is published is often one of the important pieces of information that users are concerned about.A clear and readable time format not only enhances user experience but also helps to improve the professionalism of website content.AnQi CMS is an efficient and customizable content management system that provides a flexible way to control the display of various information in templates, including the publishing time of articles.

2025-11-07

How to display the user's submitted comment content and avatar in the website comment section??

Displaying user comments on the website is a key element in enhancing user interaction and content vitality.For websites using AnQiCMS, its powerful template tag system makes this operation intuitive and flexible.This article will thoroughly introduce how to clearly display user-submitted comments in the website's comment section, accompanied by their unique avatars, thereby enriching the website's user experience.--- ### Understanding the Basics of AnQi CMS Comment Function Firstly, we need to understand how comment content operates in AnQi CMS

2025-11-07

How to display website traffic statistics in the background in the form of charts?

In website operation, understanding and analyzing traffic data is a key link in formulating effective strategies and optimizing website performance.AnQiCMS (AnQiCMS) fully understands this, and therefore provides an intuitive and convenient traffic statistics function in the background, allowing operators to easily grasp all the data of the website in the form of charts, thereby better driving content and marketing decisions.The traffic statistics feature of Anqi CMS is designed to provide a comprehensive view of website performance.It not only records the user's visit behavior, but also pays special attention to the activities of search engine spiders, which is crucial for SEO work.Through the background data statistics module

2025-11-07

How to use the `archiveFilters` tag to implement multiple condition combination filtering on the front end?

AnQiCMS provides flexible and powerful content management capabilities, one very practical feature is to use the `archiveFilters` tag to implement multi-condition combination filtering on the front-end.This undoubtedly greatly enhances the user experience and the discoverability of content for websites that are rich in content and require users to search for information based on different dimensions, such as product displays, real estate rentals, recruitment information, and so on.Let's delve deeper into how to use the `archiveFilters` tag to build an intuitive and efficient filtering system for your website.

2025-11-07

How to use the `tagList` tag to display the associated tag (Tag) cloud of the article?

AnqiCMS provides a series of powerful and flexible tags to help us manage and display website content more efficiently.Among many features, the article tag (Tag) is a very practical feature that can effectively organize content, enhance the internal link structure of the website, and make it convenient for visitors to quickly find related topics of interest.Today, let's delve into how to use the `tagList` tag to elegantly display related tags in the AnqiCMS template, and even build a dynamic 'tag cloud'.

2025-11-07

How to batch modify keywords in the article content in the background and synchronize them to the front display?

In website content operation, the accuracy and timeliness of keywords are crucial.With market changes or SEO strategy adjustments, we often need to make batch modifications to the keywords of a large number of articles on the website.If done manually, it will undoubtedly consume a lot of time and effort.幸运的是,AnQiCMS(AnQiCMS)提供了高效的批量关键词替换功能,让这一process变得得心应手,并能确保修改后的内容无缝同步到前台显示。

2025-11-07