In today's highly competitive online environment, every detail of a website can affect its performance in search engines.As an experienced website operation expert, I fully understand the key role played by structured data (Structured Data) in improving website visibility, and Json-LD, as the format recommended by search engines like Google, is even more crucial.For corporate websites in particular, how to accurately and dynamically display a company's contact information to search engines, such as phone numbers and addresses, not only enhances local search visibility but also greatly improves user trust.
Today, we will delve deeply into how to cleverly reference the background in Json-LD in AnQiCMS (AnQi CMS)contactThe contact information configured in the label. AnQiCMS provides great convenience for content operation with its efficient, customizable features, and this dynamic reference mechanism is a reflection of its flexibility.
Json-LD and contact information: the foundation of enhancing website credibility
Let's briefly review the importance of Json-LD.It is a data format based on JSON that allows webmasters to embed structured data directly into web pages.This data is not visible to users but can be understood by search engine robots, thus helping search engines better interpret web content.
For businesses, presenting core contact information (such as company name, phone number, physical address, business hours, etc.) in the form of Json-LD is an effective way to build a digital identity for the company.This not only helps search engines display richer snippets in search results, such as displaying company phone numbers or map information, but also subtly conveys the professionalism and reliability of the company.Imagine if users can directly see your company's phone number and address in search results, wouldn't it be easier for them to click and contact you?
How does AnQiCMS manage your enterprise contact information?
AnQiCMS understands the importance of enterprise contact information management and therefore provides a "Contact Information Settings" function in the background. Here, you can centrally configure the various contact information of the company, such as:
- Contact (UserName)
- Contact Phone (Cellphone)
- Contact Address (Address)
- Contact Email (Email)
- WeChat (Wechat) and WeChat QR code (Qrcode)
- and various social media links (such as WhatsApp, Facebook, Twitter, etc.)
Even, AnQiCMS also allows you to customize more contact information fields according to your business needs. Once these pieces of information are configured in the background, they can be flexibly called in the front-end pages through AnQiCMS's powerful template tag system, and the most commonly used one iscontactLabel. For example, you can{% contact with name="Cellphone" %}to directly obtain the phone number set in the background.
Core issue: How to dynamically reference these contact methods in Json-LD?
Now, the key question is: We already know how to manage contact information centrally in the AnQiCMS backend, and we also know how tocontactHow to seamlessly integrate these dynamic data into the Json-LD structured data without manually modifying the Json-LD code each time you change the phone number or address?
Maintaining Json-LD manually is not only inefficient but also prone to errors, especially when managing multiple sites or frequently updating contact information.The advantage of AnQiCMS lies in the flexibility of its templates, which is enough to meet this need.
Solution:jsonLdwith the tag andcontactcombine tags beautifully
AnQiCMS provides a namedjsonLdThe dedicated tag that allows you to customize the Json-LD content of the page. The core of solving dynamic reference contact methods is right herejsonLdInside the tag, using AnQiCMS template syntax, combiningcontacttags to retrieve the data configured in the background.
jsonLdThe usage of the tag is relatively intuitive, it acts as a block-level tag where you can write JSON code that conforms to the Json-LD specification. AnQiCMS will intelligently process this content and output it to the page.<head>Area (usually).
Here is a specific code example demonstrating how to dynamically reference the background configuration contact information in Json-LD:
{% jsonLd %}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "{% system with name='SiteName' %}",
"image": "{% system with name='SiteLogo' %}",
"telephone": "{% contact with name='Cellphone' %}",
"address": {
"@type": "PostalAddress",
"streetAddress": "{% contact with name='Address' %}",
"addressLocality": "您的城市", {# 假设城市信息需要单独填写或从其他地方获取 #}
"addressRegion": "您的省份", {# 假设省份信息需要单独填写或从其他地方获取 #}
"postalCode": "100000", {# 假设邮政编码需要单独填写或从其他地方获取 #}
"addressCountry": "CN"
},
"url": "{% system with name='BaseUrl' %}",
"openingHours": "Mo,Tu,We,Th,Fr 09:00-18:00", {# 假设营业时间需要单独填写 #}
"contactPoint": {
"@type": "ContactPoint",
"telephone": "{% contact with name='Cellphone' %}",
"contactType": "customer service"
}
}
</script>
{% endjsonLd %}
Code analysis and practical tips:
{% jsonLd %}...{% endjsonLd %}This is the Json-LD custom tag block provided by AnQiCMS, all your custom Json-LD content should be placed here.@contextand@typeThis is the foundation of Json-LD,@contextdefines the vocabulary of data semantics (usually Schema.org),@typethen indicates the type of entity you are describing, for example,LocalBusinessOr (local business) typeOrganization(Organization)."name": "{% system with name='SiteName' %}"Here we not only refer to the contact information, but also dynamically refer to the website name (SiteName) and website logo (SiteLogo) configured in the background "Global Function Settings" as the enterprise name.This demonstrates the collaborative ability of AnQiCMS tags."telephone": "{% contact with name='Cellphone' %}": This is the core! We go directly through.contactthe tag, toname='Cellphone'The parameter dynamically retrieves the phone number configured in the background "Contact Settings".If the phone number is updated, you only need to modify it once in the background, and all Json-LD structured data referencing the label will be automatically updated."address": {...}: Similarly, we go through.{% contact with name='Address' %}Dynamically obtained the detailed address of the company. Please note, Schema.org'sPostalAddressThe type requires more detailed address segmentation (such as street, city, province, postal code, country), if your backend only provides a complete address, you may need to manually split it, or add more detailed address fields in the backend for this call.|safeFilterIn some cases, when Json-LD content contains special characters or HTML entities, the AnQiCMS template engine may automatically escape them to ensure security. AlthoughjsonLdThe tag usually contains built-in processing, but if you encounter Json-LD parsing errors, you can try adding it after dynamic content output|safeFilter, for example{{ someVar|safe }}Ensure that the content is output as is without escaping. However, for Json-LD which is a plain text JSON format, this is usually not necessary|safe.
Operation steps and precautions:
- The background configuration is completeEnsure that the relevant information in the "Contact Information Settings" and "Global Function Settings" of AnQiCMS background is filled in completely and accurately.
- Select the template fileAdd the above Json-LD code to the public header file of your website template (for example
base.htmlorheader.htmlusually before the<head>Inside the label,</head>tag), so that it can take effect on all pages. - Json-LD validationAfter adding the code, be sure to use the Google Structured Data Testing Tool or the Rich Results Test to verify your webpage.This can help you check for syntax errors in Json-LD code, as well as whether search engines can correctly parse your data.
- Adjust as needed: In the example
LocalBusinessType is just one of them, you can adjust according to your business type (such asOrganization/Restaurant/ServiceChoose a more appropriate Schema.org type, and supplement more related fields, such as business hours (openingHours), price range (priceRange), geographic coordinates (geoThese information can also be obtained through backend custom fields andcontacttags orsystemdynamic tags.
Summary
AnQiCMS provides a powerful and flexible template system that allows website operators to easily manage content and optimize SEO. By cleverly combiningjsonLdwith the tag andcontactas well assystemThe label, we can not only achieve the dynamic reference of contact information, but also ensure that the structured data of the website is always synchronized with the background configuration, greatly improving the operation efficiency and the search engine friendliness of the website.This 'one-time configuration, use anywhere' strategy is exactly the embodiment of AnQiCMS in helping small and medium-sized enterprises and content operation teams improve their competitiveness.
Frequently Asked Questions (FAQ)
Q1: Can reference in Json-LD?systemInformation such as the website name or Logo configured in the tag?A1: Absolutely. As shown in the article example, you can use{% system with name='SiteName' %}Dynamically obtain the website name or use{% system with name='SiteLogo' %}Get the website logo address. AnQiCMS'ssystemThe label can call all the configuration items in the background "Global Function Settings" to keep the basic site information in Json-LD dynamicly updated.
Q2: What will be displayed in Json-LD if I have not configured a contact method in the background (for example, if I have not filled in WhatsApp)?A2: If a contact information field in the background is empty, thencontactThe output at this location will also be an empty string. In Json-LD, this is typically represented by the field having an empty string value (for example"telephone": ""This will not cause a Json-LD parsing error, but it is recommended to fill in as much information as possible in the background, or add conditional judgment in the template, if a field is empty, do not output the Json-LD attribute to maintain the simplicity and validity of Json-LD.
Q3: BesidesOrganizationorLocalBusinessWhat are the Json-LD types that can be applied to this dynamic reference method?A3: This dynamic reference method is applicable to all Json-LD types that need to include contact information (or any other information that can be obtained through AnQiCMS tags). For example, inArticleIn the (article) type, you can dynamically refer topublisher(Publisher)'snameandlogo; inProductIn the (product) type, you can refer toseller(Seller)'s contact information. The core principles are injsonLdWithin the tag, use the AnQiCMS template syntax (such ascontact/systemand tags) to dynamically fill in the corresponding Json-LD attribute values.