In website operation, maintaining search engine friendliness is one of the key factors in improving website visibility.Among them, the 'Canonical URL' plays a crucial role.It acts like a compass for search engines, telling them which page is the 'main version' of the content, thereby effectively avoiding ranking dispersion problems caused by content repetition or similarity.For content operators, correctly setting and displaying standard links is the foundation for ensuring that website content is efficiently crawled and indexed by search engines.
AnQiCMS (AnQiCMS) as a system focusing on enterprise-level content management and SEO optimization naturally considers 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 if there are multiple access paths to a page (such as a URL with parameters), you can specify here which one is the authoritative version you want the search engine to index.This is especially useful for the multilingual versions of international sites or marketing pages with tracking parameters.
How do you dynamically present the specification link set up in the background in the HTML code of the website's frontend?Anqi CMS provides a simple and efficient template tag to achieve this.The standard link is usually placed on the page<head>Area, with<link rel="canonical" href="[您的规范链接]" />existing in the form of.
In the Anqi CMS template system, you can usetdktags to obtain the standard link of the page.tdkTags were originally designed to centrally manage page titles (Title), keywords (Keywords), and descriptions (Description) and also conveniently integrate with standard linksCanonicalUrlthe acquisition.
To dynamically display the specification link of the current page, you just need to add the following code snippet to the<head>part:
{%- 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 attempts to retrieve the value named from the meta information of the current pageCanonicalUrland assign it to a variable namedcanonical_urlthe variable. Here{%-and-%}Used to remove the blank lines generated by the tag line, making the generated HTML code cleaner.
Next,{%- if canonical_url %}This line is a conditional judgment. Its purpose is to checkcanonical_urlIs the variable empty. Only when you fill in the content in the 'standard link' field in the background, will this variable have a value.
Ifcanonical_urlthere is a value, then<link rel="canonical" href="{{ canonical_url }}" />This line of code will be rendered to the page where{{ canonical_url }}The actual specification link address will be replaced. This conditional rendering ensures that the tag will only be output on the page when there is a clear specification link, thus avoiding the output of an empty or unnecessary specification link tag.
You usually place this code in your common header template file (for exampletemplate/您的模板名/partial/header.htmlorbash.html)的<head>Label inside. So, regardless of which page calls this header template, it can automatically check and display the corresponding specification link.
In this way, Anqi CMS helps you easily manage the key SEO elements of your website.You can flexibly specify the canonical link for each page in the background, and the template will intelligently recognize and output this information to ensure that the search engine can accurately understand the authoritative version of your website content, thereby optimizing the performance of your website in search results.
Frequently Asked Questions (FAQ)
Ask: Why doesn't my page display the standard link tags?Answer: First, please check whether the 'standard link' field in the 'other parameters' section of the relevant document edited in the Anqi CMS background is filled in correctly. If this field is empty, the conditional judgment in the template (
{%- if canonical_url %}It will prevent its rendering. Next, make sure that you have correctly added the above code snippet to the template file.<head>And the template cache has been updated.Ask: Should I set the standard link on all pages?Answer: Not all pages require manual setting of the standard link.For pages with unique content and no other access path, search engines usually can correctly identify their authority.However, it is very important to set clear specifications for links when there are pages with highly similar content, multiple pages with parameterized URLs (such as filtering, sorting result pages), non-first pages in a series of paginated content, or when there is duplicate content on both PC and mobile ends of your website.It helps to concentrate the page authority to the main version you specify, avoiding the dispersion of rankings due to duplicate content.
Ask: If I haven't manually set the 'standard link' field, will Anqi CMS automatically generate one?Answer: AnQi CMS will not automatically generate one if you do not set it manually
<link rel="canonical">tag. It will prioritize respecting your explicit configuration in the background. If you do not fill in this field, throughtdkTags retrieved from comments.CanonicalUrlThe value will be empty, at this time the condition judgment in the template will ensure that this tag is not output. This allows you to fully control the standard link strategy of each page.