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.