Drupal SEO — Metatag, XML Sitemap and Search Engine Optimization
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:
- Go to Configuration > Search and metadata > Metatag
- Click "Global" to configure defaults
- 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:
- Go to Configuration > Search and metadata > Metatag
- Click on a content type (e.g., Article)
- 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:
- Go to Structure > Content types > Article > Manage fields
- Add a new field of type "Metatag"
- 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
- Go to Configuration > Search and metadata > XML Sitemap
- 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
- Go to Google Search Console
- Add your site property
- Under Sitemaps, submit
https://example.com/sitemap.xml
Google Search Console Verification
Add verification meta tag:
- Go to Configuration > Search and metadata > Metatag
- Click "Global" > "Advanced"
- 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
- Go to Configuration > Search and metadata > Metatag
- Click on a content type (e.g., Article)
- Click "Schema.org" tab
- 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
- Go to Configuration > Web Services > Google Analytics
- Enter your GA4 measurement ID
- 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
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.
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.
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.
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.
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
How does the Metatag module use tokens to generate unique meta descriptions for each page?
What is the purpose of an XML sitemap and how do you submit it to Google Search Console?
How does Schema.org structured data affect search result appearance? Give an example of a rich snippet.
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
Mini Project
Goal: Implement a complete SEO layer for a Drupal site.
- Install Metatag, XML Sitemap, Schema.org Metatag, Google Analytics, and Redirect modules
- Configure global meta tags with token-based title and description
- Create per-content type meta tag templates for Article and Basic Page
- Add Open Graph and Twitter Card tags to the Article content type
- Configure XML Sitemap with appropriate priority and changefreq
- Add Schema.org Article markup to Article nodes
- Generate the sitemap and verify it at /sitemap.xml
- Enable Google Analytics with your measurement ID
- 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