Skip to content

Drupal SEO — Metatag, XML Sitemap and Search Engine Optimization

DodaTech Updated 2026-06-27 8 min read

In this tutorial, you'll learn how to optimize Drupal for search engines — from configuring the Metatag module for meta titles and descriptions to generating XML sitemaps, adding Schema.org structured data, and implementing SEO best practices for higher rankings.

What You'll Learn

  • Configuring global and per-content type meta tags with the Metatag module
  • Generating XML sitemaps and submitting them to Google Search Console
  • Adding Open Graph and Twitter Card tags for social media sharing
  • Implementing Schema.org structured data
  • SEO best practices for Drupal including URL structure and Core Web Vitals

Why It Matters

Search engines are the primary source of traffic for most websites. A well-optimized Drupal site can rank on the first page of Google for competitive keywords. Drupal's modular architecture gives you complete control over SEO elements: meta tags, sitemaps, structured data, and URL structure. Without proper SEO configuration, even the best content remains invisible. The modules covered in this tutorial are the standard toolkit used by professional Drupal SEO practitioners worldwide.

Real-World Use

An e-commerce site running on Drupal Commerce wants to rank for product-related keywords. They use Metatag to generate unique meta titles and descriptions for each product using tokens. The XML Sitemap module creates a sitemap that includes all product pages with appropriate priority and update frequency. Schema.org product markup adds rich snippets to search results showing price, availability, and reviews. Within three months, organic traffic increases by 40%.

Learning Path

flowchart LR
  A[Caching] --> B[SEO]
  B --> C[Multilingual]
  C --> D[User Roles]
  D --> E[User Management]
  E --> F[Security Hardening]
  F --> G[Custom Modules]

The Metatag Module

Metatag is the most important SEO module for Drupal. It gives you full control over HTML meta tags.

composer require drupal/metatag
drush en metatag

Global Meta Tags

Global defaults apply to all pages unless overridden:

  1. Go to Configuration > Search and metadata > Metatag
  2. Click "Global" to configure defaults
  3. Set:
# Global meta tag defaults:
title: '[current-page:title] | [site:name]'
description: '[current-page:description]'
abstract: '[site:name] - [site:slogan]'
keywords: 'drupal, [current-page:title]'

Per-Content Type Meta Tags

Override global defaults for specific content types:

  1. Go to Configuration > Search and metadata > Metatag
  2. Click on a content type (e.g., Article)
  3. Configure tokens:
# Article content type meta tags:
title: '[node:title] | [site:name]'
description: '[node:field_meta_description]'
og_title: '[node:title]'
og_description: '[node:field_meta_description]'
og_image: '[node:field_image:entity:url]'

Per-Entity Meta Tags

Enable a Metatag field on entities for per-page overrides:

  1. Go to Structure > Content types > Article > Manage fields
  2. Add a new field of type "Metatag"
  3. Content editors can now set custom meta tags per node

Open Graph Tags

Open Graph tags control how content appears when shared on Facebook, LinkedIn, and other platforms.

# Open Graph configuration:
og_title: '[node:title]'
og_description: '[node:summary]'
og_type: article
og_image: '[node:field_image:entity:url]'
og_url: '[current-page:url:absolute]'
og_site_name: '[site:name]'
og_locale: en_US

Twitter Cards

Twitter Cards control how content appears in tweets.

# Twitter Card configuration:
twitter_cards_type: summary_large_image
twitter_cards_title: '[node:title]'
twitter_cards_description: '[node:summary]'
twitter_cards_image: '[node:field_image:entity:url]'

XML Sitemap Module

The XML Sitemap module generates sitemap.xml files for search engines.

composer require drupal/xmlsitemap
drush en xmlsitemap

Configuration

  1. Go to Configuration > Search and metadata > XML Sitemap
  2. Configure default inclusion settings:
# XML Sitemap configuration:
default:
  include: true
  priority: 0.5
  changefreq: weekly
content_types:
  article:
    include: true
    priority: 0.8
    changefreq: daily
  page:
    include: true
    priority: 0.6
    changefreq: weekly
  product:
    include: true
    priority: 0.9
    changefreq: daily

Regenerating the Sitemap

# Regenerate sitemap:
drush xmlsitemap:regenerate

# Check sitemap status:
drush xmlsitemap:status

Submitting to Google Search Console

  1. Go to Google Search Console
  2. Add your site property
  3. Under Sitemaps, submit https://example.com/sitemap.xml

Google Search Console Verification

Add verification meta tag:

  1. Go to Configuration > Search and metadata > Metatag
  2. Click "Global" > "Advanced"
  3. Add the Google Search Console verification tag:
google_verification: 'your-verification-code'

Alternatively, verify via DNS TXT record or HTML file upload.

SEO Checklist Module

The SEO Checklist module provides a guided checklist for common SEO tasks:

composer require drupal/seo_checklist
drush en seo_checklist

It checks:

  • Meta tags are configured for all content types
  • XML sitemap is generated
  • Clean URLs are enabled
  • Redirect module is installed
  • robots.txt is configured
  • 404 pages are customized
  • Image alt tags are used

Schema.org Structured Data

The Schema.org Metatag module adds structured data markup:

composer require drupal/schema_metatag
drush en schema_metatag

Adding Schema.org Types

  1. Go to Configuration > Search and metadata > Metatag
  2. Click on a content type (e.g., Article)
  3. Click "Schema.org" tab
  4. Select the schema type:
# Schema.org Article markup:
schema_article:
  type: Article
  name: '[node:title]'
  description: '[node:summary]'
  datePublished: '[node:created:html_date]'
  dateModified: '[node:changed:html_date]'
  author:
    type: Person
    name: '[node:author:display-name]'
  image:
    type: ImageObject
    url: '[node:field_image:entity:url]'

Available Schema Types

  • Article — news articles and blog posts
  • Product — e-commerce product pages
  • Event — event listings
  • Organization — about page
  • Person — author or profile pages
  • Recipe — recipe pages
  • FAQPage — FAQ pages
  • BreadcrumbList — navigation breadcrumbs

Google Analytics Integration

composer require drupal/google_analytics
drush en google_analytics
  1. Go to Configuration > Web Services > Google Analytics
  2. Enter your GA4 measurement ID
  3. Configure tracking scope:
google_analytics:
  account: 'G-XXXXXXXXXX'
  visibility:
    request_path_mode: 0
    user_role_mode: 0
    user_roles:
      anonymous: anonymous
      authenticated: authenticated

URL Structure for SEO

Drupal's Pathauto module (covered in tutorial 17) generates SEO-friendly URLs:

# SEO-optimized URL patterns:
pattern: '[node:content-type]/[node:title]'
# Result: /articles/how-to-optimize-drupal-seo

Best practices for SEO URLs:

Keep URLs short and descriptive. Use hyphens between words. Avoid dates in URLs unless content is time-sensitive. Use lowercase. Do not change URLs without 301 redirects.

Core Web Vitals Optimization

Core Web Vitals are Google's performance metrics that affect rankings:

Largest Contentful Paint (LCP)

Optimize images with responsive image styles. Use next-gen formats (WebP). Lazy load below-the-fold images. Minimize server response time.

First Input Delay (FID)

Defer non-critical JavaScript. Remove unused JavaScript. Use the defer attribute on script tags.

Cumulative Layout Shift (CLS)

Set explicit dimensions on images and videos. Reserve space for ads and embeds. Do not inject content above existing content without space allocation.

# Image style for responsive images:
image_style:
  name: responsive_hero
  effects:
    - id: image_scale_and_crop
      data:
        width: 1200
        height: 630

Hreflang Tags for Multilingual SEO

For multilingual sites, add hreflang tags:

# Metatag hreflang configuration:
hreflang:
  en: '[current-page:url:absolute]'
  fr: '[current-page:url:absolute]/fr'
  de: '[current-page:url:absolute]/de'

Common Mistakes

  1. Duplicate meta descriptions across pages: Using the same meta description for all pages reduces click-through rates. Use tokens to generate unique descriptions per page.

  2. Not submitting sitemap to Google Search Console: Generating a sitemap is only half the work. You must submit the sitemap URL in Google Search Console for Google to discover it.

  3. Missing Open Graph and Twitter Card tags: Social media platforms use these tags for link previews. Without them, shared links show generic text and no image.

  4. Ignoring Core Web Vitals: Google's ranking algorithm considers LCP, FID, and CLS. A technically well-optimized Drupal site that ignores these metrics can rank below slower competitors.

  5. Changing URLs without redirects: When you update a URL alias without creating a 301 redirect, all links to the old URL return 404 errors, losing accumulated SEO value.

Practice Questions

  1. How does the Metatag module use tokens to generate unique meta descriptions for each page?

  2. What is the purpose of an XML sitemap and how do you submit it to Google Search Console?

  3. How does Schema.org structured data affect search result appearance? Give an example of a rich snippet.

  4. Challenge: Create an SEO Strategy for a recipe website built on Drupal. Define the meta tag template for recipe pages (using tokens for recipe name, description, and image), the Schema.org type and properties to use, the XML sitemap priority and changefreq for recipes, the social sharing tags needed, and the Core Web Vitals optimizations required for a recipe site with multiple images per page.

FAQ

What is the Metatag module in Drupal?

Metatag allows you to manage HTML meta tags including title, description, Open Graph, Twitter Cards, and Schema.org structured data. It supports token-based values for dynamic content per page.

How do I generate an XML sitemap in Drupal?

Install the XML Sitemap module, configure inclusion settings per content type, and run drush xmlsitemap:regenerate. Submit the sitemap URL (https://example.com/sitemap.xml) to Google Search Console.

What are Open Graph tags?

Open Graph tags are HTML meta tags that control how content appears when shared on social media platforms like Facebook and LinkedIn. They specify the title, description, image, and URL for shared links.

How do I add Schema.org structured data to Drupal?

Install the Schema.org Metatag module (schema_metatag), go to Configuration > Metatag, select a content type, and configure the schema type (Article, Product, Event, etc.) with property values using tokens.

What are Core Web Vitals?

Core Web Vitals are three performance metrics Google uses as ranking signals: Largest Contentful Paint (loading performance), First Input Delay (interactivity), and Cumulative Layout Shift (visual stability). Optimize images, defer JavaScript, and set element dimensions.

Mini Project

Goal: Implement a complete SEO layer for a Drupal site.

  1. Install Metatag, XML Sitemap, Schema.org Metatag, Google Analytics, and Redirect modules
  2. Configure global meta tags with token-based title and description
  3. Create per-content type meta tag templates for Article and Basic Page
  4. Add Open Graph and Twitter Card tags to the Article content type
  5. Configure XML Sitemap with appropriate priority and changefreq
  6. Add Schema.org Article markup to Article nodes
  7. Generate the sitemap and verify it at /sitemap.xml
  8. Enable Google Analytics with your measurement ID
  9. Verify your meta tags using Google's Rich Results Test tool

What's Next

Now that you understand Drupal SEO, proceed to multilingual Drupal to learn how to build multi-language sites. After that, explore user roles and permissions for access control.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro