Simple XML sitemap
Generates standard-compliant hreflang XML sitemaps to enhance SEO, notifies search engines of website changes via IndexNow and sitemap ping protocols, and provides a framework for developing custom sitemap types.
simple_sitemap
Install
composer require 'drupal/simple_sitemap:^4.2'
composer require 'drupal/simple_sitemap:^4.1'
Overview
Simple XML Sitemap is a comprehensive SEO module that generates XML sitemaps conforming to the Google hreflang standard. The module indexes most Drupal content entity types out of the box including nodes, taxonomy terms, menu links, users, and contributed entity types like commerce products.
The module supports multiple sitemap instances with different types and configurations, multilingual hreflang support, image indexation, custom links, and Views integration through submodules. The sitemap generation is performed via queue processing for optimal performance on large sites.
Two optional submodules extend functionality: Simple XML Sitemap (Search engines) enables automatic submission to search engines via the IndexNow protocol and traditional sitemap ping, while Simple XML Sitemap (Views) provides integration with the Views module for indexing views with arguments.
The module provides extensive API methods for programmatic sitemap management, including entity and custom link configuration, sitemap generation, and plugin extensibility through custom Sitemap Generator and URL Generator plugins.
Features
- Generates standard-compliant XML sitemaps following Google's hreflang specification for multilingual sites
- Indexes all content entity types including nodes, taxonomy terms, menu links, users, and commerce products
- Supports multiple sitemap instances with different configurations accessible at unique URLs
- Automatic sitemap generation via cron with configurable intervals
- Manual generation via admin UI, Drush commands, or programmatic API
- Sitemap chunking with automatic index generation when exceeding the maximum links threshold
- Per-entity-type, per-bundle, and per-entity override settings for index inclusion, priority, change frequency, and image inclusion
- Custom link support for adding arbitrary internal paths to sitemaps
- Human-readable XSL stylesheet with sortable columns for sitemap browsing
- IndexNow protocol support for instant search engine notification of content changes
- Traditional sitemap ping submission to search engines (deprecated)
- Views integration for indexing view pages including those with arguments
- Extensible plugin architecture for custom sitemap generators and URL generators
- Queue-based generation for handling large sites with hundreds of thousands of links
- Performance tuning options including entities per queue item and generation duration settings
- Duplicate link detection and removal
- Language-specific link generation with option to skip untranslated content
- Drush commands for sitemap generation and queue management
Use Cases
Basic SEO Setup for Content Website
Enable sitemap support for Article and Page content types. Navigate to /admin/config/search/simplesitemap/entities, enable the Content (node) entity type, then click Configure. For each content type, check 'Index' and set appropriate priority (1.0 for important landing pages, 0.5 for regular content). The sitemap will be automatically generated during cron and accessible at /sitemap.xml.
Multilingual Site with Hreflang
For multilingual sites, the module automatically generates hreflang alternate URLs for all translations. Enable 'Skip non-existent translations' in settings to only include links for languages where content actually exists. Optionally enable 'Remove hreflang markup in HTML' to avoid duplicate hreflang declarations since Google recommends having them in either the HTML or sitemap, not both.
Large Site Performance Optimization
For sites with hundreds of thousands of entities: increase 'Entities per queue item' to 200-500 to reduce database queries, set 'Maximum links in a sitemap' to 10000 to create more manageable chunks, increase 'Sitemap generation max duration' to 30 seconds if PHP timeout allows, and consider disabling 'Exclude duplicate links' if memory is limited.
Instant Search Engine Notification with IndexNow
Enable the simple_sitemap_engines submodule, navigate to /admin/config/search/simplesitemap/engines/settings, enable 'Submit changes to IndexNow capable engines', and generate a verification key. When content is created or updated, search engines are notified immediately. For production, add the key to settings.php: $settings['simple_sitemap_engines.index_now.key'] = 'your-key';
Sitemap for Views with Arguments
Enable the simple_sitemap_views submodule to index view pages. Edit your view, go to the display settings, and configure 'Simple XML Sitemap' settings. For views with arguments (like taxonomy term filters), the module tracks argument combinations used by visitors and generates sitemap entries for each variation. Set 'Maximum display variations' to limit the number of indexed argument combinations.
Multiple Sitemaps for Different Content Types
Create separate sitemaps for different audiences (e.g., products sitemap for e-commerce, blog sitemap for content). Add new sitemaps at /admin/config/search/simplesitemap/variants/add, then configure which entity bundles are indexed in each sitemap via the entity bundle settings. Use the sitemap index type to create an index listing all sitemaps.
Programmatic Sitemap Management
Use the Generator service API to programmatically manage sitemaps: $generator = \Drupal::service('simple_sitemap.generator'); Enable an entity type: $generator->entityManager()->enableEntityType('commerce_product'); Set bundle settings: $generator->entityManager()->setSitemaps(['default'])->setBundleSettings('commerce_product', 'default', ['index' => TRUE, 'priority' => 0.8]); Trigger regeneration: $generator->rebuildQueue()->generate();
Custom Links for Non-Entity Pages
Add custom internal paths that aren't entities to sitemaps. Navigate to /admin/config/search/simplesitemap/custom and enter paths like '/about-us 0.8 monthly' (path, priority, changefreq). Programmatically add custom links: $generator->customLinkManager()->setSitemaps(['default'])->add('/custom-page', ['priority' => '0.7', 'changefreq' => 'weekly']);
Tips
- Use the XSL stylesheet option to make sitemaps human-readable with sortable columns - useful for debugging and client presentations
- The sitemap index feature allows creating an index of multiple sitemaps - enable it and set as default to have /sitemap.xml list all your sitemaps
- Entity instance settings on edit forms allow overriding bundle defaults - useful for excluding specific pages or boosting important content
- Run the included performance test script to measure generation speed: drush scr modules/simple_sitemap/tests/scripts/performance_test.php
- IndexNow is preferred over traditional sitemap ping as it notifies multiple search engines with a single request and provides instant indexing
- Consider storing the IndexNow key in settings.php rather than state for better persistence across environment syncs
- The module automatically respects entity access - only content accessible to anonymous users is included in the sitemap
- Use hook_simple_sitemap_links_alter() for complex filtering logic that can't be achieved through the UI
- Custom URL generator plugins can be created to support custom entity types or external data sources
- The module's queue-based approach means generation can continue across multiple cron runs without losing progress
Technical Details
Admin Pages 10
/admin/config/search/simplesitemap
Main overview page listing all configured sitemaps with their status, generation progress, and actions. Shows the number of links, chunk count, and last generation timestamp for each sitemap.
/admin/config/search/simplesitemap/settings
Configure global sitemap settings including generation behavior, performance tuning, language options, and advanced settings.
/admin/config/search/simplesitemap/entities
Enable sitemap support for entity types and view which bundles are currently indexed in each sitemap.
/admin/config/search/simplesitemap/entities/{entity_type_id}
Configure sitemap settings for each bundle of an entity type. Settings can be configured per-sitemap for each bundle.
/admin/config/search/simplesitemap/custom
Add custom internal Drupal paths to specific sitemaps with optional priority and change frequency settings.
/admin/config/search/simplesitemap/types
Manage sitemap types which define the structure and URL generators used by sitemaps.
/admin/config/search/simplesitemap/variants/add
Create a new sitemap instance with a specific type.
/admin/config/search/simplesitemap/types/add
Create a new sitemap type with specific generator plugins.
/admin/config/search/simplesitemap/engines/settings
Configure IndexNow instant notification and sitemap ping submission to search engines (requires simple_sitemap_engines submodule).
/admin/config/search/simplesitemap/views
Overview of views that are included in sitemaps (requires simple_sitemap_views submodule).
Permissions 3
Hooks 9
hook_simple_sitemap_entity_process
Act on an entity before it is processed for sitemap generation. Can be used to modify the entity or throw SkipElementException to exclude it from the sitemap.
hook_simple_sitemap_links_alter
Alter the generated link data before a sitemap chunk is saved. Called for every sitemap chunk during generation.
hook_simple_sitemap_arbitrary_links_alter
Add arbitrary links to sitemaps. Works with sitemaps using the 'arbitrary' URL generator plugin. Links are not validated.
hook_simple_sitemap_attributes_alter
Alter sitemap XML attributes before document generation. Allows adding, modifying, or removing XML namespace declarations.
hook_simple_sitemap_index_attributes_alter
Alter sitemap index XML attributes before document generation.
hook_simple_sitemap_url_generators_alter
Alter properties of URL generator plugins or remove them entirely.
hook_simple_sitemap_sitemap_generators_alter
Alter properties of sitemap generator plugins or remove them entirely.
hook_entity_query_tag__simple_sitemap_alter
Alter the entity query used to fetch entities for sitemap generation. Uses Drupal's tagged query system.
hook_entity_query_tag__ENTITY_TYPE__simple_sitemap_alter
Alter the entity query for a specific entity type during sitemap generation.
Drush Commands 2
drush simple-sitemap:generate
Regenerate all sitemaps or continue generation from the queue. If nothing is queued, rebuilds the queue for all sitemaps first.
drush simple-sitemap:rebuild-queue
Delete the existing queue and queue elements for all or specific sitemaps for upcoming generation.
Troubleshooting 6
Ensure entity types are enabled at /admin/config/search/simplesitemap/entities and bundles are configured to be indexed. Check that 'Index' is checked for the desired bundles. Verify that content exists and is accessible to anonymous users. Run cron or manually trigger generation at the sitemaps page.
Reduce 'Entities per queue item' in settings to lower memory usage. Decrease 'Maximum links in a sitemap' to create smaller chunks. Lower 'Sitemap generation max duration' to complete smaller batches. Consider running generation via Drush (drush ssg) which typically has higher limits than web requests.
Set the 'Default base URL' in advanced settings to override the automatically detected URL. This is especially important when running cron from command line where Drupal cannot determine the correct site URL.
Verify the verification key is generated at /admin/config/search/simplesitemap/engines/settings. Ensure the key file is accessible at /simple_sitemap_engines/index_now_key/[key]. Check that entities are included in sitemap settings. For production, store the key in settings.php for persistence across deployments.
Enable the simple_sitemap_views submodule. Ensure the 'views' URL generator is added to your sitemap type. Edit the view and configure sitemap settings in the display options. For views with arguments, visitors must first access the view with those arguments before they're indexed.
Enable 'Exclude duplicate links' in advanced settings. Check for path aliases or URL rewrites that might create duplicate paths. Review hook implementations that might be modifying URLs. Ensure entity canonical URLs are correctly configured.
Security Notes 4
- The 'administer sitemap settings' permission is marked as restricted access due to its administrative capabilities
- Sitemaps only include content accessible to anonymous users by default, but custom hooks may bypass access checks
- The IndexNow verification key should be treated as sensitive - store in settings.php rather than configuration for production
- Custom links added via hooks are not validated for access - ensure they point to publicly accessible content