Hello!As an experienced website operations expert, I fully understand that in daily work, we not only need to pay attention to the quality of website content, but also to the impact of technical details on SEO.The 'Canonical URL' is one of the crucial details that can effectively solve the problem of duplicate content on websites, concentrate page authority, and thus improve search engine rankings.

Today, let's delve into how to customize the AnQiCMS templatetdkwithin the tagCanonicalUrlThe existence or absence of fields can be output smartly and elegantly, which not only makes our website code more tidy but also avoids unnecessary SEO risks.


Intelligent output specification link: AnQiCMS template inCanonicalUrlConditional judgment practice

In the realm of website operation, Search Engine Optimization (SEO) has always been one of the core strategies.And among the numerous SEO technical details, the canonical URL plays a crucial role.It is like a compass, clearly telling search engines which page is the 'original' one you want indexed and ranked, thereby effectively avoiding weight dispersion and ranking decline due to content duplication (such as URLs with different parameters, PC and mobile content being the same but with different URLs, etc.).

AnQiCMS as a system designed for efficient content management, deeply understands the SEO way, and provides many tools at the system level to help our website stand out in search engines. This includes fine-grained configuration of TDK (Title, Description, Keywords), as well as features such as pseudo-static and 301 redirection. Today, we will focus on how to utilize the powerful template tag features of AnQiCMS to achieveCanonicalUrlThe intelligent condition output.

The importance of standard links and the SEO considerations of AnQiCMS

Let's briefly review the value of the specification link. Imagine that you have an article on your website, and its URL might behttps://yourdomain.com/article/100[en] Because of various reasons (such as sharing, ad tracking, internal link structure, etc.), it may also be inhttps://yourdomain.com/article/100?source=baidu/https://yourdomain.com/article/100/index.htmlAccessed in such a form.In the eyes of search engines, these may all be different pages carrying the same content, which forms 'duplicate content'.<link rel="canonical" href="[首选URL]" />Tags, tell search engines that the real authoritative version is regardless of which URL is accessed[首选URL].

AnQiCMS was designed with these SEO requirements in mind from the very beginning.In the core feature list of the project, we can see a clear mention of 'Advanced SEO Tools', including Sitemap generation, keyword library management, and the 'TDK Configuration' we are discussing today.Moreover, AnQiCMS's good support for pseudo-static and 301 redirection also lays a foundation for constructing SEO-friendly URL structures.CanonicalUrlThe powerful template engine is also provided, allowing us to accurately present these backend configurations on the front-end page.

tdkTags: Templated presentation of SEO elements

In the template system of AnQiCMS,tdkTags are a versatile SEO information extraction tool.It allows us to easily retrieve the page's title (Title), keywords (Keywords), description (Description), and today's main character—the canonical link (CanonicalUrl).This information can be personalized in the background document management, category management, or single-page management.CanonicalUrl.

tdkThe basic usage of the label is very intuitive, usually{% tdk 变量名称 with name="字段名称" %}.nameThe parameter is used to specify which specific field of the TDK we want to obtain, such asname="CanonicalUrl".变量名称Then allow us to temporarily store the value obtained in a temporary variable for subsequent logical judgment.

Step by step: ImplementationCanonicalUrlConditional output

Now, let's build step by step the intelligent output in AnQiCMS templateCanonicalUrlThe logic. The core of this process is 'condition judgment'——only when the background explicitly sets for the current pageCanonicalUrlwe output the corresponding one in the page HTML header when<link>Labels, otherwise keep silent, avoid outputting an empty value or unnecessary labels.

  1. getCanonicalUrlof the valueWe first need to calltdkTranslate the content of the JSON array to English: [ { "key":0,"value":"Label to try to obtain the normative link address of the current page. We will assign this value to a temporary variable, such as "}canonical.

    {%- tdk canonical with name="CanonicalUrl" %}
    

    Here are the{%-Syntax is a small trick, which means removing the whitespace at the beginning of the tag, it can help us generate cleaner HTML code.canonicalThe link value set by the backend is carried now, if the backend is not set, it will be an empty value.

  2. Perform conditional judgmentNext, we need to judge thiscanonicalDoes the variable really contain a valid URL? AnQiCMS template engine supports similar to Django'sifLogical judgment tag, which makes our conditional judgment very simple.

    {%- if canonical %}
    

    The meaning of this statement is: ifcanonicalthe variable has a value (i.e., it is not empty), thenifCode within the block.

  3. output the standard link tagIfcanonicalThe variable indeed has a value, and we can safely output the standard HTML link tag.

    <link rel="canonical" href="{{canonical}}" />
    

    {{canonical}}We can dynamically insert the previously obtained standard link address intohrefin attributes.

  4. Integrate code blockIntegrate the above steps into a complete and intelligent one.CanonicalUrlThe output logic code block is as follows:

    {%- tdk canonical with name="CanonicalUrl" %}
    {%- if canonical %}
    <link rel="canonical" href="{{canonical}}" />
    {%- endif %}
    

    This code is usually placed in the website template's<head>area, for example in yourbase.htmlordetail.htmlIn the document detail page template file. In this way, our website will only generate the corresponding link when it is explicitly set in the background.<link rel="canonical">Label, maintained the brevity of code and the rigor of logic.

Operation points and precautions

  • CanonicalUrlSetting location: In AnQiCMS background, set for articles, products, or single pagesCanonicalUrlThe location is usually in the "Other Parameters" or "SEO Settings" area of the editing page, looking for the input field named "Standard Link".For the category page, similar settings can also be found in the category editing page.
  • Priority[en] : Generally, the page'sCanonicalUrlSet with the highest priority, followed by category settings, and finally global settings (if supported).When not explicitly set, the system may default to using the actual URL of the current page as the standard link, or simply not output it, which reflects the value of our conditional judgment.
  • check the output effect[en] : After deploying the code, be sure to view the page source code through the browser (right-click -> View Page Source), check<head>Is the area output correct?<link rel="canonical" href="..." />Label, and confirm.hrefIs the URL within what you expect to be the preferred URL?
  • Avoid misuse.The specification link is powerful, but not the more the better. It should only be applied to pages where there is indeed a risk of duplicate content.hrefThe URL pointed to must be the unique and preferred version of the content. Errors or misuse of specification links may cause indexing issues for search engines, which can actually harm SEO effects.

Summary

In AnQiCMS, utilizetdktag and flexible template judgment mechanism, achieveCanonicalUrlThe intelligent condition output is an important link in improving the SEO refined management level of website operation.It not only helps us effectively avoid duplicate content issues, concentrate page weight, but also keeps our template code elegant and efficient.As a website operations expert, mastering these details will make our website navigate more steadily and long-term in the sea of search engines.


Common Questions (FAQ)

  1. What is a canonical URL? What help does it provide for SEO?A canonical URL is an HTML tag (`}]}