In daily content operations, we often need to embed various external or internal links in articles, product descriptions, and even in category descriptions and other text content.However, manually converting these plain text URL strings one by one into clickable HTML links is not only time-consuming and labor-intensive, but also prone to link errors due to negligence, which affects user experience and search engine optimization.
AnQiCMS is well aware of this pain point, therefore it provides a clever and efficient mechanism that can intelligently identify URL strings in text, automatically parse them into clickable links with correct HTML tags, greatly enhancing the efficiency and accuracy of content publishing.
The core of intelligent parsing:urlizeandurlizetruncFilter
AnQiCMS is a powerful and flexible template system that uses its built-in Filters feature to automatically parse URLs in text. Among them,urlizeandurlizetruncThese filters play a core role.
When you output a piece of text that may contain a URL in the template, just simply applyurlizeFilter, AnQiCMS can automatically identify text that containshttp:///https://orwww.URL strings that start with, as well as email addresses that match the format, and convert them to standard<a>Label. It is worth mentioning that in order to better comply with SEO standards, AnQiCMS will also add a default external link to these links when parsing themrel="nofollow"Attribute, effectively avoid unnecessary weight loss.
For example, suppose you have a piece of text.{{ archiveContent }}Contains访问我们的官网:https://en.anqicms.com,或者发送邮件至 [email protected].You can use it in the template like this:
<div>
{{ archiveContent|urlize|safe }}
</div>
The page will eventually display as:
<div>
访问我们的官网:<a href="https://en.anqicms.com" rel="nofollow">https://en.anqicms.com</a>,或者发送邮件至 <a href="mailto:[email protected]">[email protected]</a>
</div>
Please note that we have additionally used|safeFilter. This is because the AnQiCMS template system, to prevent cross-site scripting (XSS) attacks, defaults to escaping all output content to HTML.urlizeThe filter generates a string with HTML tags, if not using|safethese tags themselves will also be escaped into entity characters, causing links to not display normally. Use|safeExplicitly tell the system that this content is safe and does not need to be escaped.
In some cases, you may want to maintain the clickable nature of a link while also controlling its display length on the page, to avoid overly long URLs affecting the overall layout. At this point,urlizetruncThe filter comes into play. It is similar tourlizethe function, but after parsing, it can truncate the link text to the specified character length and add an ellipsis at the end (...)。For example, if you want to display a link with no more than 15 characters:
<div>
{{ archiveContent|urlizetrunc:15|safe }}
</div>
This way, long URLs will be intelligently truncated to keep the page tidy.
Global considerations for link management
AnQiCMS intelligent processing of links does not stop at text parsing.As a mature content management system, it also provides a variety of link management functions, collectively building an efficient, secure, and SEO-friendly content ecosystem.
For example, in the content settings, you can choose whether to automatically filter external links. If you choose not to filter, the system will automatically add external links to the content.rel="nofollow"Label, thisurlizeThe default behavior of the filter is consistent, further strengthening the internal control of SEO.
Moreover, AnQiCMS also has a powerful "site-wide content replacement" feature, allowing you to update keywords or links on the website in bulk with one click.This can quickly and accurately complete large-scale link maintenance work when adjusting website content strategy, changing URL structure, or renaming the brand name, greatly improving operational efficiency.
For optimizing internal links, the "anchor text management" feature of AnQiCMS also plays an important role.You can preset keywords and corresponding links, so the system can automatically identify keywords and add anchor text links when publishing content. This not only improves the browsing experience of users within the site but also has a positive impact on the crawling and ranking of search engines.
From a broader perspective, functions such as 'fake static rules' and '301 redirect management' ensure the standardization, friendliness, and maintainability of URLs at the overall architecture level of the website, laying a solid foundation for the website's SEO performance.
Summary
In summary, AnQiCMS passes throughurlizeandurlizetruncSuch an intelligent filter, supplemented by other perfect link management tools, greatly simplifies the processing process of URLs in the content.The operator only needs to focus on creating high-quality content, without worrying about manual link conversion, adding SEO properties, and maintaining global links.This automated and systematic management approach not only saves a lot of time and effort, but also ensures the professionalism of website content, the smoothness of user experience, and provides strong support for search engine optimization.
Frequently Asked Questions (FAQ)
1. Why when usingurlizeorurlizetruncPlus after the filter,|safe?AnQiCMS's template system, for website security, defaults to escaping all passed through{{变量}}grammatically output content to HTML.urlizeorurlizetruncThe filter will convert plain text URLs into HTML codes with tags.<a>If you do not add|safethese tags will be escaped as.<a>the tag itself will be escaped into<a>Entity characters that cause the page to only display text and cannot be clicked. Use|safeExplicitly tell the system that this part of the HTML content generated by the filter is safe and can be output directly without further escaping.
2.urlizeThe filter will automatically addrel="nofollow"Should I add the attribute?Yes,urlizeThe filter will automatically addrel="nofollow"Property. This design is to follow the suggestions of search engines, to help websites better control the transmission of link weight, and avoid unnecessary SEO risks.At the same time, AnQiCMS also provides the option 'Whether to automatically filter external links' in the 'Content Settings' section of the backend, further refining the strategy for handling external links.
3. Can I customizeurlizethe style of the parsed link (for example, adding a CSS class)?
urlizeThe filter is mainly responsible for converting text to<a>Label, it does not add custom CSS classes by default. If you need to add styles to these automatically parsed links, you can do so through CSS selectors, for example, for<a>Labels or combine with the parent element for styling definition. If your needs are more complex and require dynamic addition of specific attributes when generating links, then you may need to consider manually adding links through a rich text editor at the time of content publication, or consider deeper template or system customization.