In content operation and website SEO optimization, the title plays a crucial role.An精心构建的SEO title can attract the attention of users and effectively improve the visibility of the page in search engine results pages (SERP).Among them, the character length of the title is a detail that should not be ignored.Too long may cause the title to be truncated, affecting information delivery; too short may not fully utilize the display space, missing the opportunity to attract users.
AutoCMS (AutoCMS) is a powerful content management system that provides a rich set of tools for SEO optimization.It allows users to finely control core SEO elements such as TDK (Title, Description, Keywords).For the website title (usually composed of page title and website name), being able to dynamically obtain and preview its character length is undoubtedly a very practical feature for content editors.This helps us make precise adjustments to the SEO title before publishing content, ensuring its**effectiveness in search engines.
Get website nameSiteName
In AnQiCMS template system, get the website nameSiteNameVery direct. We mainly use the built-in system.systemLabel. This label is specifically used to retrieve various global information configured in the "System Settings" background, including our website name.
Using the following template code, you can easily get the name of the current website:
{# 使用 system 标签获取网站名称,并将其赋值给一个变量 siteName #}
{% system siteName with name="SiteName" %}
{# 此时,siteName 变量就包含了您在后台设置的网站名称 #}
<p>您的网站名称是:{{ siteName }}</p>
This code first retrieves the latest 5 articles by{% system siteName with name="SiteName" %}Read out the "Website Name" configured in the background and store it in a name ofsiteNameThe template variable is in. After that, you can refer to this variable anywhere in the templatesiteNamevariable to display or process your website name.
Dynamic calculationSiteNameof the character length
Since we have already been able to obtainSiteName,then calculating its character length becomes a piece of cake. AnQiCMS's template engine is built-in with various filters (filters).lengthFilter is specifically used to calculate the length of strings, arrays, or objects. For Chinese characters,lengthThe filter calculates it by individual characters, which is consistent with our common word counting habits and is very suitable for SEO title optimization of Chinese websites.
To calculatesiteNameThe character length, just pass it as a parameterlengthFilter:
{# 假设 siteName 变量已通过前面的步骤获取到 #}
<p>网站名称“{{ siteName }}”的字符长度是:{{ siteName|length }} 个字符。</p>
With this simple line of code, you can accurately display the number of characters used by the website name during template rendering.
toSiteNameLength integration into SEO title preview
In practical SEO work, a complete page title usually consists of the 'Page Content Title', 'separator', and 'Website Name'.For example, '[Page Title] - [Website Name]'.tdkLabels provide great flexibility when processing page titles, and they can even automatically append the website name to the end of the page title according to your configuration.
tdkTagsname="Title"The parameter is used to get the SEO title of the current page. If we set thetdktagsiteName=true, it will automatically append the website name to it. At the same time,sepThe parameter allows us to customize the delimiter.
For example, if you want to preview a complete SEO title containing the website name and calculate its total length, you can do it like this:
{# 1. 获取完整的SEO标题。
tdk 标签会根据当前页面类型(文章、分类、单页等)和后台配置,
生成页面标题,并自动拼接网站名称(siteName=true)和默认分隔符(默认为" - ")。
您可以根据需要,通过 sep 参数自定义分隔符,例如 sep=" | "。
#}
{% tdk fullSeoTitle with name="Title" siteName=true sep=" - " %}
{# 2. 在模板中展示这个完整的SEO标题预览 #}
<p>SEO标题最终预览:</p>
<div style="border: 1px solid #ccc; padding: 10px; margin-bottom: 15px; background-color: #f9f9f9;">
<strong>{{ fullSeoTitle }}</strong>
</div>
{# 3. 计算并显示这个完整SEO标题的字符总长度 #}
<p>该SEO标题总字符长度:<span style="font-weight: bold; color: #007bff;">{{ fullSeoTitle|length }}</span> 个字符。</p>
{# 提示:
大多数搜索引擎对标题的显示长度有推荐范围(例如,中文建议在30-35个字符,英文50-60个字符)。
利用这个长度显示,您可以更精确地调整标题,以避免被截断,确保**的搜索引擎展示效果。
#}
With the above code snippet, you can directly see the complete SEO title containing the website name and its accurate character length during template rendering.This is a very effective auxiliary tool for content editors, helping them better control the quality of titles and improve the performance of the page on search engines.
Practical suggestions and precautions
- Length optimizationPlease ensure to pay attention to the recommended range of title character length by the search engine.Through this dynamic preview method provided by AnQiCMS, you can ensure that the title can fully display the core information without being truncated due to its length.
- Separator selection:
tdkTagssepParameters allow you to flexibly select a separator. Common ones include hyphen (-),