AutoCMS (AutoCMS) is a system focused on enterprise-level content management and SEO optimization, naturally considering the importance of standard links.When you are editing articles, products, or other documents in the background, you will find a field named "Standard Link" in the "Other Parameters" section of the document.Here you can manually specify a standard URL for the current page.This means that if you have pages with similar content, or pages with multiple access paths (such as URLs with parameters), you can specify which one you want the search engine to index as the authoritative version here.This is particularly useful for the multi-language versions of the international site, or marketing pages with tracking parameters.
How can you dynamically present the specification link set in the background in the HTML code of the website's frontend?AutoCMS provides a simple and efficient template tag to achieve this.<head>Area,<link rel="canonical" href="[您的规范链接]" />exists in the form of.
In the template system of AnQi CMS, you can usetdktags to obtain the standard link of the page.tdkThe label design was initially intended for centralized management of page titles (Title), keywords (Keywords), and descriptions (Description) as metadata, and it also conveniently integrates support for standard linksCanonicalUrlThe acquisition of.
To dynamically display the specification link of the current page, you just need to add the following code snippet to the template file.<head>Part: add the following code snippet:
{%- tdk canonical_url with name="CanonicalUrl" %}
{%- if canonical_url %}
<link rel="canonical" href="{{ canonical_url }}" />
{%- endif %}
Let's explain the function of this code:
First,{%- tdk canonical_url with name="CanonicalUrl" %}This line of code tries to obtain the value named from the metadata of the current page.CanonicalUrland assigns it to a variable named.canonical_urlHere is the{%-and-%}Used to remove the blank lines generated by tag removal, making the generated HTML code more tidy.
紧接着,{%- if canonical_url %}This line is a conditional judgment. Its function is to checkcanonical_urlThe variable is empty. Only when you fill in content in the "standard link" field on the backend, this variable will have a value.
Ifcanonical_urlit has a value, then<link rel="canonical" href="{{ canonical_url }}" />This line of code will be rendered to the page, where{{ canonical_url }}The content will be replaced with the actual specification link address.This conditional rendering ensures that the tag is only output when there is a clear specification link, avoiding the output of an empty or unnecessary specification link tag.
You usually place this code in your general header template file (for exampletemplate/您的模板名/partial/header.htmlorbash.html) of<head>Label inside. In this way, no matter which page calls this header template, it can automatically check and display the corresponding specification link.
Through this way, A Safe CMS helps you easily manage the key SEO elements of the website.You can flexibly specify the canonical link for each page in the background, and the template will intelligently recognize and output this information, ensuring that search engines can accurately understand the authoritative version of your website content, thereby optimizing the performance of your website in search results.
Common Questions (FAQ)
问:Why doesn't my page display the standard link tags?答:Firstly, please check if the 'standard link' field in the 'other parameters' section of the documents edited in the AnQi CMS backend is filled in correctly. If this field is empty, the conditional judgment in the template (
{%- if canonical_url %})will prevent it from rendering. Secondly, please make sure that you have correctly added the above code snippet to your template file.<head>area, and the template cache has been updated.问:我应该在所有页面都设置规范链接吗?答:Not all pages require manual setting of standard links.For pages that contain unique content and have no other access path, search engines typically can correctly identify their authority.However, it is very important to set clear specifications for link when there are pages with highly similar content, multiple parameterized URLs (such as filtering, sorting results pages), non-first pages in a pagination content series, or when there are duplicate contents for both PC and mobile versions on your website.It helps to concentrate the page authority to the main version you specify, avoiding ranking dispersion due to duplicate content.
问:如果我没有手动设置“规范的链接”字段,安企CMS会自动生成一个吗?答:English CMS will not automatically generate one for you without your manual setting
<link rel="canonical">tags. It will give priority to the explicit configuration you make in the background. If you do not fill in this field, throughtdkthe tags you getCanonicalUrlThe content will be empty, at this time, the conditional judgment in the template will ensure that this tag is not output. This allows you to have complete control over the specification link strategy for each page.