XML sitemap
Creates XML sitemaps conforming to the sitemaps.org specification to help search engines index your site content efficiently.
xmlsitemap
Install
composer require 'drupal/xmlsitemap:^2.0'
composer require 'drupal/xmlsitemap:8.x-1.5'
composer require 'drupal/xmlsitemap:8.x-1.2'
Overview
XML Sitemap automatically creates a sitemap that conforms to the sitemaps.org protocol. This helps search engines keep their search results up to date by providing a structured list of URLs on your site along with metadata about when they were last modified, how often they change, and their relative priority.
The module supports all content entity types in Drupal including nodes, taxonomy terms, users, and menu links. You can configure which entity types and bundles should be included in the sitemap, set default priorities and change frequencies, and override these settings on individual items.
The sitemap is generated as cached XML files that are served directly to search engine crawlers, ensuring optimal performance even for large sites with many links.
Features
- Generates XML sitemaps conforming to the sitemaps.org specification
- Supports all content entity types (nodes, users, taxonomy terms, menu links, etc.)
- Configurable inclusion/exclusion per entity type and bundle
- Customizable priority (0.0-1.0) and change frequency settings per content type
- Per-item override of sitemap settings for fine-grained control
- Automatic sitemap regeneration via cron when content changes
- Sitemap index support for sites with more than 50,000 links
- Gzip compression support for sitemap files
- Human-readable XSL stylesheet for viewing sitemaps in browsers
- Multilingual support with per-language sitemap links
- Integration with robots.txt module to automatically add sitemap reference
- Integration with Metatag module to exclude noindex content
- Views integration for querying sitemap link data
- Drush commands for regenerating and rebuilding sitemaps
Use Cases
Basic SEO Setup
After installing the module, enable the node entity type and select which content types should be included (e.g., Article, Page). Set appropriate priorities - important landing pages at 0.8-0.9, blog posts at 0.5-0.6, and archive pages at 0.3-0.4. Run cron to generate the sitemap and submit it to Google Search Console.
Large Site with Multiple Sitemaps
For sites with more than 50,000 URLs, the module automatically creates a sitemap index with multiple sitemap chunks. Configure the chunk size in advanced settings if needed. Consider disabling cron regeneration and using Drush commands during low-traffic periods for better performance.
Multilingual Site
When the Language module is enabled, XML Sitemap automatically creates language-specific sitemap contexts. Each language gets its own sitemap with the appropriate hreflang attributes. Ensure content translations are properly configured for all included content types.
E-commerce Product Catalog
Enable the product entity type for sitemap inclusion. Set products to high priority (0.7-0.8) with daily or weekly change frequency. Use the per-item override to boost featured products or demote out-of-stock items. Consider using hook_xmlsitemap_link_alter to dynamically adjust priorities based on inventory.
Excluding Specific Content
Use the per-item XML Sitemap settings on content edit forms to exclude specific items. For bulk exclusions, use the bundle settings to disable entire content types. If using Metatag, set items to noindex and enable the metatag exclusion option.
Custom Links
Enable the XML Sitemap Custom submodule to add URLs that aren't automatically detected, such as static files, external microsites, or legacy URLs. Custom links support the same priority and change frequency settings.
Search Engine Submission
Enable the XML Sitemap Engines submodule to automatically notify search engines when the sitemap is updated. Configure Google submission and optionally add custom ping URLs for other search engines.
Tips
- Set realistic priorities - use the full 0.0-1.0 range to differentiate content importance
- Configure change frequencies based on actual update patterns, not desired crawl rates
- Use the XSL stylesheet option for easier debugging - view sitemap.xml in a browser
- Monitor sitemap status in Status Report for warnings about regeneration or file size
- Consider using Drush commands in cron for better control over regeneration timing
- Enable developer mode temporarily when debugging sitemap issues
- Always test that anonymous users can access content before expecting it in the sitemap
Technical Details
Admin Pages 6
/admin/config/search/xmlsitemap
Main administration page listing all XML sitemaps. Shows sitemap ID, context, links count, chunks, and last updated time. Provides operations to edit or delete individual sitemaps.
/admin/config/search/xmlsitemap/settings
Configure global XML Sitemap settings including regeneration timing, output format, and advanced options.
/admin/config/search/xmlsitemap/entities/settings
Select which entity types and bundles should be included in the XML sitemap.
/admin/config/search/xmlsitemap/settings/{entity}/{bundle}
Configure XML sitemap settings for a specific entity type bundle (e.g., Article content type).
/admin/config/search/xmlsitemap/rebuild
Completely rebuild the XML sitemap data by re-indexing all content. Use this after initial installation or in emergencies.
/admin/config/search/xmlsitemap/add
Create a new XML sitemap with a specific context (e.g., for a different language).
Permissions 2
Hooks 6
hook_xmlsitemap_link_info
Provide information on the type of links this module provides.
hook_xmlsitemap_link_alter
Alter the data of a sitemap link before saving.
hook_xmlsitemap_element_alter
Alter XML element content for individual sitemap entries.
hook_xmlsitemap_root_attributes_alter
Alter root element attributes of the sitemap.
hook_xmlsitemap_context_info
Define available sitemap contexts.
hook_xmlsitemap_context
Provide current context values.
Drush Commands 3
drush xmlsitemap:regenerate
Regenerate the XML Sitemap files. Use this to rebuild cached sitemap files after content changes.
drush xmlsitemap:rebuild
Dump and re-process all possible XML Sitemap data, then regenerate files. Use this for a complete rebuild of sitemap link data.
drush xmlsitemap:index
Process un-indexed XML Sitemap links. Indexes new content that hasn't been added to the sitemap yet.
Troubleshooting 6
Run cron to generate the sitemap files. Check that the sitemap cache directory is writable. Verify at least one entity type bundle is enabled for inclusion.
Verify the content type is enabled in Sitemap Entities settings. Check that individual items are set to 'Include' and have 'Published' status. Ensure anonymous users can view the content.
Decrease the batch limit in advanced settings. Disable URL alias prefetching. Consider using Drush commands instead of web-based regeneration.
Check that cron is running and cron regeneration is not disabled. Verify the minimum lifetime has elapsed since last generation. Run cron manually or use Drush to regenerate.
Increase the chunk size in advanced settings. Consider excluding low-priority content types or archives. Maximum is 50,000 links per chunk and 50,000 chunks total.
Remove any static sitemap.xml file from the web root. XML Sitemap needs to serve the sitemap dynamically through Drupal routing.
Security Notes 4
- The 'administer xmlsitemap' permission is marked as restricted and should only be given to trusted administrators
- Sitemap files may expose the URL structure of your site to anyone
- Ensure content access permissions are properly configured as the sitemap respects anonymous user access
- The module checks entity access before including links, but custom link additions bypass this