The goal of this tutorial is for you to install the Simple XML Sitemap module and have it generate a sitemap for your Drupal site.
A sitemap XML file acts as a roadmap for search engines, enabling them to discover and understand the structure of your website. By providing a clear and organized representation of your site's content, you can improve its visibility in search engine result pages (SERPs). The Simple Sitemap XML module simplifies this process by generating an XML sitemap automatically for your Drupal website.
Add/Enable the Drupal Module to your Codebase
Add the Module
Depending on how your Drupal site is setup, there are different ways to add the module to your codebase. The most popular was is through Composer and that can be accomplished using the following command:
composer require drupal/simple_sitemap
If you would like additional information about installing modules on your Drupal site, you can reference the Acquia Docs page on this topic.
Enable the Module
After the module has been added to your codebase, you need to enable the module to make it available to configure and use.
Navigate to Extend in the Admin Toolbar, when you get to the Module listing page you can filter the list by typing "simple" which will shorten the list of modules so you can find the one you are looking for. The Simple Sitemap XML module comes with 3 components but we are only covering the "Simple Sitemap XML" module in this tutorial.
Check off "Simple XML Sitemap" and click the "Install" button.
Global Settings Configuration for the Sitemap
After installing the Simple Sitemap XML module, the default sitemap is created and it provides you with some global configuration settings for the created sitemap. You can navigate to Configuration > Search and Metadata > Simple Sitemap XML in the Admin Toolbar to get the configuration page.
Select the "Settings" tab on the start configuration page that you went to.
On the settings tab you will have some defaults selection made for you. the critical configuration changes to make are:
Regenerate the sitemap on Cron runs: You will likely be running cron frequently and this will ensure that the sitemap is updated with new content.
Default Base URL: This is important, if you've split your config for each env (Dev/Stage/Prod) make sure you set the Base URL accordingly to make sure the right URL is setup in the sitemap.
Other configuration items provide guidance on the recommended defaults and you can set them up for your specific use case.
Sitemap Configuration - Content Inclusion
After installing the module it will generate a default sitemap file for you, that will be available at /sitemap.xml on your domain.
However, we need to do some additional work to get content listed in our sitemap.
Go to Configuration > Simple Sitemap XML in the Admin Toolbar.
To "Enable" content to be include in the sitemap, click on "Inclusion" and enabled "Content" to be added to the sitemap, we will have to configure each content type next.
Also within the "Inclusion" tab is a sub-tab to add Custom Links to the sitemap, this is helpful if you have non-content pages on your site that you would like included in your sitemap.
Add Content to the Sitemap
Once you've enabled the module, the the default configuration and activate the module to allow content to be added, you now have to configure each content type to be include in the default sitemap.
In this example, let's add the "Article" content type to the sitemap.
Navigate to Structure > Content Types > Article and scroll to the bottom of the Edit Article content type page, you will then see a section called "Simple XML Sitemap", click that Title to open that section.
Be sure to enable the following options:
"Index entities of type Article in variant Default"
If this content type is of higher priority then other content types you can set the priority.
If you want to regenerate the sitemap after saving the Content Type you can enable that as well.
On next cron run, Article content that is published will be included in the sitemap located at /sitemap.xml on your site.
We will be providing additional Tutorials in the future on configure Views for Sitemaps and the important of sitemaps for your website.
A sitemap XML file helps search engines understand the structure and content of your website, making it easier for them to crawl and index your pages. It improves the chances of your website being discovered and ranked higher in search engine results.
Yes, besides generating an XML sitemap, the Simple Sitemap XML module also provides additional features such as customizable URLs, support for multilingual sites, and the ability to exclude specific pages from the sitemap.
Yes! Besides the Simple Sitemap XML module there is also the XML Sitemap module that also provides the ability to generate a sitemap.xml file based upon the content within your Drupal site. Both modules are highly supported and will generate XML Sitemaps.
Thank You Drupal Contributors
Special Thanks to the 2 maintainers of the Simple XML Sitemap Module: