How to add structured data (JSON-LD) in the HTML header to improve search result display?

Calendar 👁️ 103

In today's highly competitive online environment, it is crucial to make your website content stand out in search engine results pages.In addition to high-quality content and an excellent keyword strategy, structured data (especially in JSON-LD format) plays an increasingly important role.It can help search engines understand the information on your page more accurately, which may result in displaying your content in a richer and more attractive form in search results (such as rich media summaries, i.e., Rich Snippets).

What is JSON-LD and why should it be used?

JSON-LD (JavaScript Object Notation for Linked Data) is a data format based on JSON that allows you to embed structured data in HTML pages.In simple terms, it is like providing a 'manual' for search engines, telling them what a certain title on a page is, who the author is, how much the product price is, and where and when the event is located, etc.

When search engines can understand this structured information, they have the opportunity to display richer visual elements in search results, such as article thumbnails, rating stars, product prices, or inventory status.These rich media summaries can significantly increase the click-through rate of your website in search results, attracting more potential users to visit your website.For websites using Anqi CMS, fully utilizing JSON-LD is a key step to improve SEO effectiveness and gain more organic traffic.

How to simplify the addition of JSON-LD in AnQi CMS

The Anqi CMS was designed with SEO in mind from the outset and includes built-in support for structured data.In most cases, you do not need to manually write complex JSON-LD code, Anqi CMS will automatically generate some basic structured data based on the type of content you publish (articles, products, etc.)

But if you need to control or extend these structured data more finely, AnQi CMS also provides flexible customization options. You can use a template system, which is named{% jsonLd %}The tag to insert or overwrite the default JSON-LD content. This tag's usage is very intuitive, allowing you to directly in the HTML header area (usuallybase.htmlWrite the JSON-LD script in this public template file, or in a specific detail page template.)

You can directly find or add it in the<head>section of the template file, for examplebase.htmlFile, or you can customize the article detail page template (such asarchive/detail.html).

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% tdk with name="Title" siteName=true %}</title>
    <meta name="keywords" content="{% tdk with name="Keywords" %}">
    <meta name="description" content="{% tdk with name="Description" %}">
    <link rel="canonical" href="{% tdk with name="CanonicalUrl" %}" />

    {# 安企CMS会自动生成基础JSON-LD。如果您想自定义或扩展,可以使用以下标签: #}
    {% jsonLd %}
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "WebPage",
        "name": "{% tdk with name="Title" %}",
        "description": "{% tdk with name="Description" %}",
        "url": "{% system with name="BaseUrl" %}",
        "publisher": {
            "@type": "Organization",
            "name": "{% system with name="SiteName" %}",
            "logo": {
                "@type": "ImageObject",
                "url": "{% system with name="SiteLogo" %}"
            }
        }
    }
    </script>
    {% endjsonLd %}

    {# 您的其他CSS和JS文件 #}
    <link rel="stylesheet" href="{% system with name="TemplateUrl" %}/css/style.css">
</head>
<body>
    {# 网站内容 #}
</body>
</html>

In the above example, we demonstrated how to use{% jsonLd %}tags to add a basic structure to a website pageWebPageType-structured data. Please note,{% jsonLd %}The content enclosed in tags, AnQi CMS will automatically merge it into the final JSON-LD output.If your custom content conflicts with the system-generated content, the custom content will take precedence over the default content.

Common JSON-LD types and their security CMS implementation

Next, let's look at some commonly used JSON-LD types, as well as how to dynamically fill in data by combining Anqi CMS template tags.

1. Article structure data

For blog posts, news reports, and other content,ArticleThe type can help search engines display article titles, authors, publication dates, thumbnails, and other information.

Suppose you are editing the template of the article detail page (for example/template/default/archive/detail.html):

{# 假设这是您的文章详情页模板内容,已经包含其他HTML结构 #}
{% extends 'base.html' %} {# 继承您的基础模板 #}

{% block head %} {# 在base.html中定义一个block用于额外head内容 #}
    {{ super() }} {# 保持父模板head内容 #}

    {%- archiveDetail archiveContent with name="Content" %} {# 先获取文章内容,用于description和image的提取 #}
    {% jsonLd %}
    <script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": "Article",
        "headline": "{% archiveDetail with name="Title" %}",
        "image": [
            "{% archiveDetail with name="Logo" %}" {# 文章缩略图 #}
        ],
        "datePublished": "{{ stampToDate(archive.CreatedTime, "2006-01-02T15:04:05+08:00") }}",
        "dateModified": "{{ stampToDate(archive.UpdatedTime, "2006-01-02T15:04:05+08:00") }}",
        "author": {
            "@type": "Person",
            "name": "{% system with name="SiteName" %}" {# 如果文章有单独作者字段,可以替换 #}
        },
        "publisher": {
            "@type": "Organization",
            "name": "{% system with name="SiteName" %}",
            "logo": {
                "@type": "ImageObject",
                "url": "{% system with name="SiteLogo" %}"
            }
        },
        "description": "{% tdk with name="Description"|truncatechars:150 %}" {# 截取描述,防止过长 #}
    }
    </script>
    {% endjsonLd %}
    {%- endarchiveDetail %}
{% endblock %}

{% block content %}
    {# 文章具体内容展示 #}
    <h1>{% archiveDetail with name="Title" %}</h1>
    <p>发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}</p>
    <div>
        {%- archiveDetail articleContent with name="Content" %}
        {{ articleContent|safe }}
        {%- endarchiveDetail %}
    </div>
{% endblock %}

In this example, we made use ofarchiveDetailtags to get the article title, thumbnail, publishing and modification time.systemtags are used to get the website name and Logo as the publisher's information.stampToDateThe filter ensures that the time format conforms to the JSON-LD requirements.

2. Product (Product) structured data

For the product detail page,ProductThe type can display product names, images, prices, inventory, reviews, etc., directly presented in the search results.

Suppose this is your product detail page template (for example/template/default/product/detail.html):

”`twig {# Product detail page template #} {% extends ‘base.html’ %}

{% block head %}

{{ super() }}

{% jsonLd %}
<script type="application/ld+json">
{
    "@context": "https://schema.org/",
    "@type": "Product",
    "name": "{% archiveDetail with name="Title" %}",
    "image": [
        "{% archiveDetail with name="Logo" %}" {# 产品主图 #}
        {# 也可以循环显示产品组图Images #}
        {%- archiveDetail productImages with name="Images" %}
        {%- for img in productImages %}
        ,"{{ img }}"
        {%- endfor %}
        {%- endarchiveDetail %}
    ],
    "description": "{% tdk with name="Description"|truncatechars:200 %}",
    "sku": "{% archiveDetail with name="ProductSKU

Related articles

How to deploy multiple AnQiCMS sites on the same server and ensure their independent display?

Deploying multiple websites on the same server while ensuring that they run and display independently is a common need for many content operators.For AnQiCMS users, this is not only feasible but also very efficient.The Anqi CMS leverages its powerful multi-site management features, allowing you to easily manage multiple brand sites, sub-sites, or content branches with just one core program.Next, we will discuss in detail how to deploy and manage multiple security CMS sites cleverly on the same server, so that they operate independently without interfering with each other.### Core Concept

2025-11-08

How to display the current year or other system time information in the template?

In website operation, keeping your content up-to-date in real-time, especially information like the year or date of system time, can not only enhance the professionalism of the website but also provide users with more accurate references.AnQiCMS as a flexible and efficient content management system provides a variety of convenient ways for you to easily implement this requirement. Next, let's learn how to flexibly display the current year or other system time information in the AnQiCMS template.### Display the current system time——`{% now %}`

2025-11-08

How does the automatic compression of images and the handling of large images in content settings affect page display performance?

In website operation, images are indispensable elements that enrich content and attract users.However, if image processing is not handled properly, the large file size often becomes the culprit that slows down page loading speed, thereby affecting user experience and search engine optimization (SEO) performance.AnQiCMS provides a series of powerful image processing features in its content settings, aimed at helping us easily optimize images and significantly improve the display performance of the website.When a visitor opens a page, the browser needs to download all the resources on the page, including text, styles, scripts, and images.If the image file is too large

2025-11-08

How do static rules affect the display form and SEO-friendliness of website URLs?

## Static rule of AnQi CMS: How to create a URL structure that users and search engines both love In the operation of a website, the URL is not only the path for users to access the page, but also an important clue for search engines to understand and evaluate the content of the website.A clear, concise, and meaningful URL that greatly enhances user experience and website SEO performance.AnQi CMS knows this, and therefore provides a flexible and diverse static rule management function to help us easily create an ideal URL structure.What is pseudo-static and why is it so important

2025-11-08

How to enable and display captcha in the comment or message form?

In website operation, the message and comment functions are important channels for interacting with users and collecting feedback.However, this is often accompanied by the困扰 of spam and malicious flooding.To effectively filter out this unnecessary content, enabling the captcha mechanism has become a simple and efficient solution.AnQiCMS (AnQiCMS) provides us with a flexible way to easily integrate captcha functionality into comment or message forms. Next, we will learn in detail how to enable and display the captcha in Anqi CMS.### Step 1: Turn on captcha feature in the management background First

2025-11-08

How can language switch links be displayed in multilingual sites?

Build a website for global users, multilingual support is an indispensable part.AnQiCMS was designed with this in mind, providing a powerful and flexible solution for the publication and management of multilingual content.By making some simple configuration and template adjustments, we can easily implement language switching functionality on the website, allowing users of different languages to smoothly browse the website content.### AnQiCMS' multilingual capabilities AnQiCMS is inherently equipped with excellent multilingual content management capabilities

2025-11-08

How to display a user or user group in the template

In AnQi CMS template design, it is crucial to be able to flexibly display user or user group information, which is essential for building personalized, interactive website experiences.AnQi CMS provides intuitive and powerful template tags, allowing you to easily display rich information such as users' profiles and user groups on the front end of the website, thereby enhancing user engagement and the professionalism of the website.Whether you want to display the user's nickname and membership level in the article comment area or show specific content and features based on the user's identity or group, Anqi CMS provides the `userDetail` and

2025-11-08

How can you accurately convert a numeric string to a floating-point number in the Anqi CMS template?

In AnQi CMS template development, we often need to handle various types of data, where the conversion between numeric strings and floating-point numbers is a common and important requirement.For example, you may get a custom field from the background, such as a price (like "12.50"), or a numeric product inventory (like "100"), when performing mathematical operations, comparing sizes, or displaying in a specific format in the template, it is particularly important to convert it from a string type to a floating-point number accurately

2025-11-08