In content operation and website SEO optimization, the title plays a crucial role.A well-crafted SEO title can not only attract users' attention but also effectively improve the visibility of the page on the search engine results page (SERP).Among them, the character length of the title is a detail that should not be overlooked.Too long may cause the title to be truncated, affecting the transmission of information; too short may not make full use of the display space, missing the opportunity to attract users.
AnQiCMS (AnQiCMS) 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 title of the website (usually composed of the page title and the website name), being able to dynamically obtain and preview the character length is undoubtedly a very practical feature for content editors.This helps us accurately adjust the SEO title before publishing the content, ensuring its presentation effect in search engines.
Get website nameSiteName
In AnQiCMS template system, retrieve the website nameSiteNameVery direct. We mainly use the built-in system.systemThe tag is used to retrieve various global information configured in the background "System Settings", including our website name.
You can easily get the name of the current website with the following template code:
{# 使用 system 标签获取网站名称,并将其赋值给一个变量 siteName #}
{% system siteName with name="SiteName" %}
{# 此时,siteName 变量就包含了您在后台设置的网站名称 #}
<p>您的网站名称是:{{ siteName }}</p>
This code first goes through{% system siteName with name="SiteName" %}Read out the "website name" configured in the background and store it in the name ofsiteNamethe template variable. After that, you can refer to thissiteNamevariable to display or process your website name.
dynamic calculationSiteNamecharacter length of
Since we have already been able to obtainSiteNameThen, calculating its character length becomes very easy. AnQiCMS's template engine is built-in with various filters (filters), among whichlengthThe filter 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 optimizing SEO titles on Chinese websites.
To calculatesiteNameThe character length, just pass it as a parameter tolengthFilter:
{# 假设 siteName 变量已通过前面的步骤获取到 #}
<p>网站名称“{{ siteName }}”的字符长度是:{{ siteName|length }} 个字符。</p>
With this simple line of code, you can accurately display the number of characters occupied by the website name when rendering the template.
toSiteNameLength integrated into the SEO title preview
In actual SEO work, a complete page title usually consists of the 'Page Content Title', 'Separator', and 'Website Name'.For example, "[Page Title] - [Website Name]".AnQiCMS'tdkLabels provide great flexibility when handling page titles, and can even automatically append the website name to the page title after your configuration.
tdklabel'sname="Title"The parameter is used to get the SEO title of the current page. If we settdkthe tagsiteName=true, it will automatically concatenate the website name. At the same time,sepParameters allow us to customize the delimiter.
For example, if you want to preview a complete SEO title that includes 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个字符)。
利用这个长度显示,您可以更精确地调整标题,以避免被截断,确保**的搜索引擎展示效果。
#}
By the above code snippet, you can directly see the complete SEO title including the website name and its accurate character length during template rendering.This is a very effective auxiliary tool for content editors, which can help them better control the quality of titles and improve the page's performance in search engines.
Practical suggestions and precautions
- Length OptimizationPlease pay attention to the recommended range of title character length by the search engine.By using 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:
tdklabel'ssepThe parameter allows you to flexibly select a separator. Common ones include hyphen (-),