In website content operation, page title (Title) and Meta description (Description) are key elements of Search Engine Optimization (SEO).They not only directly affect the visibility and click-through rate of the website on the search engine results page (SERP), but also serve as the first window through which users convey the core content of the page.replaceThe filter can help us flexibly and dynamically adjust the keyword density of these key meta information to meet different optimization needs.

Understand the TDK management mechanism of Anqi CMS

In-depth explorationreplaceThe application of the filter requires us to first understand how the security CMS manages page titles, keywords (Keywords), and Meta descriptions (Description), which are usually abbreviated as TDK. The system determines the final TDK content according to a certain priority when generating pages:

  1. Global TDK Settings:In the background "Home Page TDK Settings", you can set the default home page title, keywords, and description for the entire website. This provides the entire site with basic SEO information.
  2. Content (document, category, single page) level TDK settings:When publishing documents, creating categories, or editing single pages, you can set SEO titles, keywords, and descriptions individually for each specific content.These settings have a higher priority than the global TDK and will override the default values of the corresponding page.
  3. Automatically extract:If you have not manually filled in the Meta description for a piece of content, the Anqi CMS will intelligently extract a portion of text from the content's brief introduction as the description.

In the template, we can usetdkLabel to get the TDK information of the current page. For example, get the page title:{% tdk with name="Title" %}Get Meta description:{% tdk with name="Description" %}These tags output the final TDK content after system priority processing.

MasterreplaceThe core function of the filter

replaceThe filter is a very practical text processing tool in the Aiqi CMS template engine, which allows us to replace a specific word or phrase in a string with another when outputting content.This provides unlimited possibilities for dynamically adjusting the keyword density in the TDK.

The basic syntax is:{{ 目标字符串 | replace:"旧词,新词" }}.

UnderstandingreplaceSeveral key points of the filter are crucial:

  • Parameter separation: 旧词and新词English commas must be used between them.,Split the content.
  • The old word is empty:If旧词Empty (i.e.,replace:",新词")replaceThe filter will insert at the beginning of the target string and after each UTF-8 character.新词This can be used to insert separators between each character.
  • New word is empty:If新词Empty (i.e.,replace:"旧词,")replaceThe filter will remove all matches from the target string.旧词This is often used to remove unnecessary characters or phrases.
  • Case sensitive:By default,replaceThe filter is case sensitive.

Let's look at a few simple examples to enhance understanding:

{{ "欢迎使用安企CMS"|replace:"安企,anqi" }}
{# 输出结果:欢迎使用anqiCMS #}

{{ "欢迎使用安企CMS"|replace:",-" }}
{# 输出结果:-欢-迎-使-用-安-企-C-M-S- #}

{{ "安企CMS,专业的CMS"|replace:"专业的CMS," }}
{# 输出结果:安企CMS, #}

By these examples, we can seereplaceThe flexibility of filters in string processing.

The key to dynamically adjusting the keyword density of page titles and Meta descriptions.

Now, we willreplaceFilter applied to the optimization practice of page title and Meta description.Our goal is to dynamically adjust at the template level without modifying the original TDK settings.

1. English dynamic optimization of the page title (Title)

假设我们有一个产品页面,其原始SEO标题是“English CMS Business Website Solution”。But we hope to emphasize the keyword 'Free Website Building' in specific promotional activities, or adjust the order and frequency of keyword appearance.

{# 1. 首先,获取当前页面经过系统处理后的最终标题 #}
{% tdk originalTitle with name="Title" %}

{# 2. 使用 replace 过滤器进行关键词替换或调整 #}
{# 示例1:将“解决方案”替换为“免费建站方案”,增加“免费建站”关键词密度 #}
{% set modifiedTitle = originalTitle|replace:"解决方案,免费建站方案" %}

{# 示例2:在标题末尾动态添加一个关键词,例如“【限时优惠】” #}
{% set modifiedTitle2 = originalTitle|add:"【限时优惠】" %} {# add过滤器用于拼接字符串 #}

{# 示例3:组合多个替换操作,例如先替换再添加 #}
{% set tempTitle = originalTitle|replace:"企业建站,网站建设" %}
{% set finalTitle = tempTitle|add:" - 安企CMS官网" %}

{# 3. 最后,将修改后的标题输出到 <title> 标签中 #}
<title>{{ finalTitle }}</title>

{# 也可以直接在 <title> 标签内进行操作,但通过 set 变量会更清晰和方便多步操作 #}
{# <title>{{ {% tdk with name="Title" %} | replace:"解决方案,免费建站方案" }}</title> #}

Here we usedseta label to define a temporary variablemodifiedTitleFirst obtaintdkthe original title output by the tag, then performreplacethe operation, and finally output to<title>Label it. This ensures the clarity and maintainability of the template code.

2. Dynamically adjust Meta description (Description)

Meta description can also be adjustedreplaceFilter can be dynamically adjusted to ensure it includes core keywords and attracts user clicks.

{# 1. 获取当前页面的Meta描述 #}
{% tdk originalDescription with name="Description" %}

{# 2. 使用 replace 过滤器调整描述内容 #}
{# 示例1:确保描述中包含某个重要的关键词,如果不存在则尝试插入,如果存在则可能替换其周边文字 #}
{% set modifiedDescription = originalDescription|replace:"高效建站,利用安企CMS高效免费建站" %}

{# 示例2:移除描述中不必要的短语,例如“本站提供” #}
{% set modifiedDescription2 = originalDescription|replace:"本站提供," %}

{# 3. 输出修改后的Meta描述 #}
<meta name="description" content="{{ modifiedDescription }}">

When adjusting the Meta description, be sure to pay attention to the fluency and readability of the description. Even to increase the keyword density, you should not sacrifice user experience.

3. Dynamic adjustment for specific content models

replaceFilters can also be combined with specific content models (such as documents)archiveDetail, ClassificationcategoryDetail, Single pagepageDetail)的数据进行更细致的动态调整。例如,您可能希望根据auto