With search engines constantly improving how they interpret content, enhancing SEO with structured data has become essential for driving organic traffic. Using Schema.org and JSON-LD with Google Schemas in Drupal, you can make your content more understandable to search engines, which can improve rankings, increase click-through rates, and even display rich snippets. This article explains how to add Schema.org and JSON-LD to Drupal, including code examples, schema types, and the benefits of structured data.
Schema.org provides a vocabulary of tags (or "schemas") that webmasters can use to improve the way search engines read and represent their pages in SERPs. JSON-LD (JavaScript Object Notation for Linked Data) is a format for structuring data as easily readable JSON code. Together, Schema.org and JSON-LD allow you to embed structured data directly into your web pages.
Integrating Schema.org with JSON-LD on a Drupal site can help in the following ways:
To implement JSON-LD in Drupal, you can use the Schema.org Metatag module or create a custom module to add JSON-LD scripts to your pages.
The Schema.org Metatag module helps add structured data to your Drupal content easily. Follow these steps:
schema_metatag
module by downloading it from the Drupal modules page.Configuration > Search and metadata > Metatag
.This module provides several built-in schemas for different content types, including articles, events, products, and more.
If you need more flexibility, you can add JSON-LD directly to your theme's HTML template files.
Example Code for Adding JSON-LD in a Twig Template
Here’s an example of adding JSON-LD for an article directly within a Drupal Twig template:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "{{ node.title.value }}",
"datePublished": "{{ node.created.value|date('c') }}",
"author": {
"@type": "Person",
"name": "{{ node.field_author.entity.name.value }}"
},
"publisher": {
"@type": "Organization",
"name": "Your Site Name",
"logo": {
"@type": "ImageObject",
"url": "https://yoursite.com/logo.png"
}
}
}
</script>
Place this script in your article template file (e.g., node--article.html.twig
). The script dynamically pulls information from the article node, creating structured data for each article on your site.
Below is a table listing common schema types and their purposes:
Schema Type | Use Case | Example JSON-LD Code |
---|---|---|
Article | For news, blog posts, or articles. |
|
Event | For promoting upcoming events. |
|
LocalBusiness | For local SEO for businesses with physical locations. |
|
Each schema type can be customized based on the content it describes. Here’s a guide for applying different schema types in Drupal:
To implement article schema on blog post pages, use the following JSON-LD script in the blog post template file:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "{{ node.title.value }}",
"datePublished": "{{ node.created.value|date('c') }}",
"author": {
"@type": "Person",
"name": "{{ node.field_author.entity.name.value }}"
}
}
</script>
Use this JSON-LD code in your event content template to add structured data for events:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Event",
"name": "{{ node.title.value }}",
"startDate": "{{ node.field_event_date.value|date('c') }}",
"location": {
"@type": "Place",
"name": "{{ node.field_location.entity.name.value }}"
}
}
</script>
If your site represents a local business, adding LocalBusiness
schema can help improve visibility in local searches:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "{{ site_name }}",
"address": {
"@type": "PostalAddress",
"streetAddress": "{{ node.field_address.value }}",
"addressLocality": "{{ node.field_city.value }}",
"addressRegion": "{{ node.field_state.value }}",
"postalCode": "{{ node.field_zip.value }}"
},
"contactPoint": {
"@type": "ContactPoint",
"telephone": "{{ node.field_phone.value }}"
}
}
</script>
Adding structured data to Drupal has significant SEO benefits:
Implementing Schema.org and JSON-LD in Drupal is a powerful way to improve SEO, enhance content discoverability, and attract more traffic. Whether you’re using the Schema.org Metatag module or custom JSON-LD scripts, structured data will help your site stand out in search results and better serve your audience. Start incorporating Schema.org and JSON-LD in your Drupal site to maximize SEO and user engagement.
Integrate structured data today and experience the difference in your search rankings!
Published By: Kartik Sharma
Updated at: 2024-11-14 08:16:17