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, all external links output by the contact information tags should be automatically addedrel="nofollow"Properties, this involves both an understanding of the core functions and mechanisms of CMS, as well as some flexible template application skills.
Firstly, let's delve into it.rel="nofollow"The meaning of the property.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 the website, avoiding passing authority to uncontrolled external sites, and handling links in advertising, sponsorship, or user-generated content.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.According to our in-depth analysis of the AnQiCMS document, its handling of external links varies in different scenarios.
For example, inContent publishingThe AnQiCMS provides a global setting, where you can choose whether to automatically filter external links in the "Background Settings" -> "Content Settings".rel="nofollow"Property. This is very effective for main content such as articles, product details, etc.
However, for something like "Contact Information Tag"contactThis is a special tag used to output specific information, its original design intention is to directly output the original data you configured in the background, including the URL. This means that if you have configured an external link in the contact information in the background, contactLabels will output this link directly by default, without auto-attachingrel="nofollow". For example, if you set a Facebook link in the background, if you access it 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: Smart UseurlizeThe filter adds a link to the contact informationrel="nofollow"
AnQiCMS provides a namedurlizeof the filter, which is exactly designed to solve this kind of problem.urlizeThe function of the filter is to identify URL strings and email addresses in the text and then convert them into clickable HTML<a>labels, andAutomatically add these generated external linksrel="nofollow"PropertyThis is the most elegant and most in line with AnQiCMS design philosophy way to achieve our goal.
The following are the specific operation steps:
定位template file:Firstly, you need to find the template file responsible for rendering the contact information of your website. This is usually located in the public part of the current template theme directory, such as
partial/footer.html/partial/header.htmlorguestbook/index.htmlWait, the specific location depends on your template design. In the AnQiCMS template design conventions, common code is usually stored inbash.htmlorpartial/the directory.Find out the usage
contactThe location of the label output link:In the template file found, find all uses of{% contact ... %}the label and itsnameparameter corresponds to the field of external links, such asFacebook/Twitter/Youtube/Instagramor your custom contact information containing a URL.For example, you might see a code snippet similar to this:
<!-- 原始模板代码示例 --> <li>Facebook: {% contact with name="Facebook" %}</li> <li>YouTube: {% contact with name="Youtube" %}</li> <li>我的自定义外部链接: {% contact with name="MyCustomLink" %}</li>Apply
urlizeFilter:Now, we need tourlizeapply thecontacton the output of the tag. At the same time, sinceurlizeThe filter generates HTML tags, and in order to ensure that the browser correctly parses these HTML codes, we also need to use them in conjunction withsafeFilter, tells AnQiCMS template engine that this part of the output is safe HTML and does not need to be escaped.The modified code example is as follows:
<!-- 经过改造的模板代码 --> <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 in
{{ }}Internal reference{% contact %}Labels, we treat them as a string that can be processed by a filter. Whencontacta URL string is output by a label,urlizeit will be wrapped withrel="nofollow"of<a>Tag, whilesafethese are guaranteed to be<a>The label can be rendered normally.If you are using
contactAssign the field obtained by the label to a variable, and then output the variable, which 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?
- Automated processing:
urlizeThe filter is specifically designed to automatically identify URLs in text and convert them into clickable links, saving the trouble of manually building<a>the tags. - built-in
nofollow:The most critical thing is that it will automatically add external links generated.rel="nofollow"Properties, which perfectly fits our needs without the need to write complex logic. - High compatibility:Whether it is the standard contact information field (such as Facebook, Youtube URL) or the field you customize through the AnQiCMS backend, which contains external links,
urlizeThe filter can be universally processed. - SEO-friendly:In this way, you can ensure that all external links output through the contact method tag are
nofollowProperties, control your external link strategy better, avoid unintentional weight loss.
After completing these modifications, remember to save your template file, and clear the cache of AnQiCMS (via the "Update Cache" feature in the backend), then visit your website's front-end 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 developer tools of the browser.
Summary
In AnQiCMS, although the contact information tag does not automatically add an external link by default.rel="nofollow",but by cleverly utilizing its built-inurlizeFilter, we can easily achieve this goal at the template level.This can not only effectively manage the website's SEO, but also ensure the flexibility and standardization of the output content.As an operations expert, mastering these optimization skills at the template level will allow you to use AnQiCMS more skillfully.
Common Questions (FAQ)
Q1: Why add an external link to the contact informationrel="nofollow"is important?
A1: Addrel="nofollow"Attributes can tell search engines not to consider this link as a recommendation or a "vote" for the target website. This is very useful in many cases: first, it can help you control