As an experienced website operations expert, I fully understand your attention to the details of website SEO, especially the handling of external links. In AnQiCMS, you need to make all external links output by the contact information label automatically addedrel="nofollow"Property, this involves not only an understanding of the core functional mechanism of CMS, but also some flexible template application skills.

First, let's delve into it in detail.rel="nofollow"The meaning of the attribute. This attribute tells the search engine not to consider this link as an 'endorsement' or 'vote' for the target website.This is crucial for controlling the 'PageRank flow' of a website, avoiding passing authority to uncontrolled external sites, and handling links in advertisements, sponsorships, or user-generated content.Add to the social media links and external service links that appear on your website contact information,nofollowIt is a wise SEO strategy that can avoid inadvertently diluting the weight of your website.

Overview of the link handling mechanism in AnQiCMS

AnQiCMS as an efficient and customizable content management system provides multi-level control in link processing.Based on our in-depth analysis of the AnQiCMS document, its handling of external links varies in different scenarios.

For example, inContent publishingIn terms, AnQiCMS provides a global setting, namely in the "Background Settings" -> "Content Settings", you can choose whether to automatically filter external links. If you select not to filter external links, the system will automatically add all external links to the published content.rel="nofollow"Property. This is very effective for article, product details and other main content.

However, for something like "Contact Information Tag" (contact)This type of label is specifically used for outputting specific information, with the original intention of directly outputting the original data you configure in the background, including URLs. This means that if you have configured an external link in your background contact information,contactThe tag will output this link directly by default without automatically appendingrel="nofollow"For example, if you set the Facebook link in the background and directly through{% contact with name="Facebook" %}Output, the result will be a purehttps://facebook.com/yourpagestring.

At this point, we need to use the powerful template tags and filter functions of AnQiCMS to achieve our goal.

Core solution: use巧妙lyurlizeFilter to add contact linkrel="nofollow"

AnQiCMS provides a namedurlizeThis filter is exactly designed to solve such problems.urlizeThe filter's role is to identify URL strings and email addresses in the text and then convert them into clickable HTML<a>the tags, andAutomatically add these generated external links torel="nofollow"propertyThis is the most elegant way to achieve our goal and is in line with the design philosophy of AnQiCMS.

The following are the specific steps:

  1. Locate the template file:Firstly, you need to find the template file responsible for rendering the contact information on your website. This is usually in the public part of the theme directory you are currently using, such aspartial/footer.html/partial/header.htmlOrguestbook/index.htmland, the specific location depends on your template design. In the AnQiCMS template design conventions, common code is usually stored inbash.htmlorpartial/directory.

  2. find usagecontactthe location of the tag output link:In the template file found, find all uses of{% contact ... %}tag and itsnameparameter corresponds to the field of external links, such asFacebook/Twitter/Youtube/Instagramor the contact information with URL you customized.

    For example, you might see a code snippet like this:

    <!-- 原始模板代码示例 -->
    <li>Facebook: {% contact with name="Facebook" %}</li>
    <li>YouTube: {% contact with name="Youtube" %}</li>
    <li>我的自定义外部链接: {% contact with name="MyCustomLink" %}</li>
    
  3. applyurlizeFilter:Now, we need to applyurlizea filter tocontactthe output of the tags. At the same time, sinceurlizeThe filter generates HTML tags, in order to ensure that the browser correctly parses these HTML codes, we also need to use it in conjunction withsafeA filter that tells the AnQiCMS template engine that this part of the output is safe HTML and does not need to be escaped.

    The following is an example of the modified code:

    <!-- 经过改造的模板代码 -->
    <li>Facebook: {{ {% contact with name="Facebook" %} | urlize | safe }}</li>
    <li>YouTube: {{ {% contact with name="Youtube" %} | urlize | safe }}</li>
    <li>我的自定义外部链接: {{ {% contact with name="MyCustomLink" %} | urlize | safe }}</li>
    

    Please note that,{{ }}Internal reference{% contact %}When a tag is encountered, it is treated as a string that can be processed by a filter. Whencontacta tag outputs a URL string,urlizeit will be wrapped in a tag withrel="nofollow"of<a>tags, whilesafeit ensures that these<a>The tag can be rendered normally.

    If you are usingcontactAfter obtaining the field, assign it to a variable and then output the variable, it will be clearer:

    <!-- 更清晰的变量赋值示例 -->
    {% contact facebookLink with name="Facebook" %}
    {% if facebookLink %} {# 判断是否有值再输出 #}
        <li>Facebook: {{ facebookLink | urlize | safe }}</li>
    {% endif %}
    
    
    {% contact youtubeLink with name="Youtube" %}
    {% if youtubeLink %}
        <li>YouTube: {{ youtubeLink | urlize | safe }}</li>
    {% endif %}
    
    
    {% contact customExternalLink with name="MyCustomLink" %}
    {% if customExternalLink %}
        <li>我的自定义外部链接: {{ customExternalLink | urlize | safe }}</li>
    {% endif %}
    

Why chooseurlizeFilter?

  1. Automated processing: urlizeThe filter is specifically designed to automatically identify URLs in text and convert them into clickable links, saving the trouble of manually constructing<a>the tags.
  2. Built-innofollow:The most critical thing is that it will automatically add properties to the generated external links.rel="nofollow"This perfectly meets our needs without the need to write complex logic.
  3. High compatibility:Whether it is a standard contact information field (such as Facebook, Youtube URL) or a field customized by you through the AnQiCMS backend that contains external links,urlizeFilters can be universally processed.
  4. SEO friendly:In this way, you can ensure that all external links output through contact information tags arenofollowProperty, better control your external link strategy, avoid unintentional weight loss.

After completing these modifications, remember to save your template file, clear the AnQiCMS cache (via the "Update Cache" function in the backend), and then visit your website's frontend to check if the external links in the contact information section have been added correctlyrel="nofollow"Property. You can verify the element by checking the browser developer tools.

Summary

Although the contact information tag in AnQiCMS does not add external links automatically by default.rel="nofollow"But by cleverly utilizing its built-inurlizeFilter, we can easily achieve this goal at the template level.This not only effectively manages the website's SEO, but also ensures the flexibility and standardization of the output content.As an operation expert, mastering these template optimization skills will allow you to use AnQiCMS more skillfully.


Frequently Asked Questions (FAQ)

Q1: Why should external links for contact information be addedrel="nofollow"be important?

Addrel="nofollow"The attribute can tell the search engine not to consider the link as a recommendation or "vote" from your website to the target website. This is very useful in many cases: first, it can help you control