How to make all external links output by AnQiCMS contact information tags automatically add the `rel="nofollow"` attribute?

Calendar 78

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

Related articles

Do I support automatically adding `tel:` and `mailto:` links to contact numbers and email addresses, AnQiCMS?

In today's website operations, improving user experience and convenience is one of the core competitive advantages.When a user sees a phone number or email address on a website and can directly click to dial or send an email, it undoubtedly greatly improves efficiency and satisfaction.So, does AnQiCMS (AnQi Content Management System) support automatically adding `tel:` and `mailto:` links to the contact phone numbers and email addresses on the website?As an experienced website operations expert, I can confidently tell you that AnQiCMS provides a flexible mechanism to meet this requirement

2025-11-06

How to implement responsive layout and optimize loading speed for WeChat QR code images in AnQiCMS template?

As an experienced website operation expert, I am well aware that in today's multi-device environment, the display effect and loading speed of website content are key factors determining user experience and search engine performance.The WeChat QR code is an important tool for connecting online and offline and promoting user conversion, and its presentation in the AnQiCMS template also requires fine-tuning.Today, let's delve into how to achieve a perfect responsive layout and optimize loading speed for your WeChat QR code image in AnQiCMS templates, providing a smooth user experience.

2025-11-06

How to truncate the contact address field in the template while retaining the complete information?

As an old soldier who deeply understands the way of CMS content operation, I know that every detail in website construction and content presentation is related to user experience and brand image.Especially when displaying key elements such as contact information, how to ensure beauty and cleanliness in a limited space while fully conveying the information, this is often a small challenge faced by operators.Today, let's delve deeply into how to cleverly truncate the display of the contact address field in the Anqi CMS template when it is too long, while ensuring that users can always obtain the complete address information.Challenge

2025-11-06

How to format phone numbers in AnQiCMS templates, for example, adding country codes or separators?

In website operation, a clear, professional and easily identifiable contact number often leaves a deep impression on users and directly affects the conversion rate.For enterprises and content creators who rely on Anqi CMS to build websites, how to elegantly display contact information in templates, making it conform to regional customs, adding country codes, or visual separators, is a key factor in improving user experience.The Anqi CMS provides us with powerful tools and methods to achieve this goal with its flexible Django template engine syntax and rich built-in filters.

2025-11-06

Whether the `Qrcode` image output by the contact information label supports custom `alt` text attribute?

As an experienced website operations expert, I know that every detail in a content management system can affect the overall performance of the website, whether it's user experience or search engine optimization (SEO).Today, let's delve deeper into the QR code image output of the contact information label in AnQiCMS (AnQiCMS), whether the `alt` text attribute supports customization, and how we can use it flexibly.### Security CMS QR code image `alt` text attribute customization: Insightful functions and practical strategies In modern website operations

2025-11-06

How to use `{% if %}` in AnQiCMS template to determine if a contact field exists or is not empty?

In the AnQiCMS template, we often need to decide whether to display a certain area or present information in a different way based on the presence or absence of content.This is especially critical for sensitive and important information such as contact details, we never want to leave a bunch of empty titles or broken links on the page.Today, as your website operations expert, I will take you in-depth to understand how to cleverly use the `{% if %}` tag in AnQiCMS templates to determine whether the contact information field exists or is not empty, making your website interface more intelligent and friendly.

2025-11-06

If an AnQiCMS contact field is empty, how can you display default text in the template instead of leaving it blank?

## AnQiCMS template optimization: How to cleverly display default text when the contact information field is empty?In website operation, maintaining the integrity of website content and user experience is crucial.AnQiCMS (AnQiCMS) provides a solid foundation for building various websites with its flexible content management and powerful template functions.

2025-11-06

The `{% contact %}` tag supports which filters to format the output content?

As an experienced website operation expert, I know that how to flexibly display and process information in a content management system is the key to improving website user experience and operational efficiency.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template engine and rich tag system.Today, let's delve into the `{% contact %}` tag and how to make your website's contact information display more exquisite and practical through its output content filters.

2025-11-06