How to Configure Schema.org Structured Data on a Drupal Site
Search engines are getting smarter, but they still rely on structured data to fully understand your content. Schema.org is the standard vocabulary that helps Google, Bing, and other platforms interpret the meaning of your pages. By adding Schema.org markup to your Drupal site, you increase the chances of appearing in rich search results like article carousels, event listings, FAQs, and product snippets.
To gain visibility, you need to describe your pages in a way machines can understand. This guide will show you how to add Schema.org markup to your Drupal site using modules, configure the correct schema types for your content, and validate that your setup is working correctly. We’ll also cover best practices to keep your structured data accurate and up to date.
Whether you are launching a new Drupal project or optimizing an existing site, proper Schema.org configuration will help search engines recognize your content and present it more effectively in results.
Installing the Required Modules
Before you can start configuring schema types, you need to install the right tools. The two key modules are Metatag and Schema.org Metatag. Metatag allows you to manage metadata across your site, and Schema.org Metatag extends that functionality by providing fields for structured data.
If you want more information about Metatags, we invite you to check out our guide on How To Optimize Drupal SEO.
If your project uses Composer, you can install both modules with a single command:
composer require drupal/metatag drupal/schema_metatag
Once the download is complete, enable the modules with Drush:
drush en metatag schema_metatag -y
Alternatively, you can enable them from the Drupal admin interface under Extend.
If you need more advanced modeling of schema types, consider adding the Schema.org Blueprints module. This tool is especially helpful when you want to create reusable configurations for complex content types like events or products.
Setting Global Schema Defaults
The first step is to configure the default schema for your entire site. This ensures that search engines understand the basics about your organization or business. From the admin menu, go to Configuration > Search and metadata > Metatag. Edit the Global defaults, and under the Schema.org section, set your Organization name, logo, and website URL.
This information will be included across your site unless you override it at the content type or node level. It’s a simple but crucial step to establish your brand identity in structured data.
Configuring Schema for Content Types
Once the global defaults are in place, you’ll want to configure schema for specific content types. Each content type may represent a different schema type. For example, articles should use the Article type, events should use Event, and product pages should use Product.
To configure a content type, navigate to the Metatag settings for that type (for example, Configuration > Search and metadata > Metatag > Article). Under the Schema.org options, choose the correct type. Then use Drupal tokens to populate the fields dynamically. For instance, you can map the headline property to the node title token, the author property to the node author, and the publication date to the node created date.
This approach ensures that every piece of content in that content type automatically outputs valid schema markup, without requiring manual entry for each node.
Adding Schema for Custom Fields
Many Drupal sites include custom fields that don’t map directly to the default schema properties. For example, you might have a field for event speakers or product SKUs. In these cases, you can either map the fields through the Schema.org Metatag configuration (if supported) or add them manually using Twig templates.
For advanced customizations, you can inject JSON-LD directly into your theme templates. Open the template file for the relevant content type, usually something like node--[type].html.twig, and insert a script block with JSON-LD markup. Use Twig variables to dynamically output field values. This method gives you full control, but it also requires careful validation to ensure accuracy.
Example: Configuring an Event Content Type
Let’s walk through a practical example. Suppose you have an Event content type with fields for title, date, location, and organizer. In the Metatag settings for Events, choose the Event schema type. Then map the properties as follows:
- Name: Use the node title token.
- Start Date and End Date: Map to your event date fields.
- Location: If you store the location as a text field, output it directly. If it’s an entity reference, use the token for the referenced entity’s name.
- Organizer: Map to a field that stores the event host.
- Image: Map to your event image field.
Once saved, every event you publish will automatically include structured data describing its key details.
Validating Your Schema Markup
After configuration, it’s important to validate your structured data. Open one of your content pages and view the page source. You should see a <script type="application/ld+json"> block with the schema properties. Copy this markup and test it using Google’s Rich Results Test or the Schema Markup Validator. These tools will highlight any missing required fields or errors that could prevent your pages from being eligible for rich results.
If you don’t see the schema in the source, clear Drupal’s cache. In some cases, you may need to review your Metatag configuration to ensure the schema settings are applied to the correct content type.
Best Practices for Schema in Drupal
Adding schema is not a one-time task. Here are some best practices to keep in mind:
- Always use JSON-LD format, which is the recommended format by Google and less disruptive to your HTML structure.
- Start with the required properties for each schema type, then expand with optional ones to increase your eligibility for rich results.
- Use Drupal tokens whenever possible so that schema values update automatically with your content.
- Keep your schema types consistent across similar content types. For example, don’t mix NewsArticle and BlogPosting for the same type of content unless you have a clear reason.
- Avoid duplicating schema by adding it both through Metatag and custom Twig templates, unless you are deliberately extending functionality.
- Revalidate your structured data after every major content model change.
Make Your Content Machine-Readable
Schema.org is an evolving standard, with new types and properties being added regularly. To keep your site compliant and competitive, update your Drupal modules periodically and check for new configuration options. It’s also a good idea to monitor Google Search Console for structured data reports, which can alert you to errors or opportunities for improvement.
Schema.org is one of the most effective ways to make your Drupal site stand out in search results. With the right module setup, thoughtful configuration, and ongoing maintenance, you can give search engines the context they need to present your content in rich, engaging ways. Whether you are marking up articles, products, or events, structured data ensures that your site communicates not just with users, but with the algorithms that shape how your brand is discovered online.