Miguel Rodríguez does effective software development.

How to generate the XML Sitemap automatically on Drupal

Sitemap

Sitemap
Attribution: 
This Article is based solely on my experiences of Drupal 7 and XML sitemap 2.
Although Drupal is a great CMS, it has not a way to generate the XML Sitemap by default, however, there is a module that makes everything so easy that you would think I am cheating you, the XML Sitemap module generates automatically the XML Sitemap of all the content depending on the options previously configured by the user, it can even send the XML Sitemap to the Search Engines (Google, Bing, ...) automatically. In this tutorial, we are going to see how to use this module to generate the XML Sitemap on Drupal.
 

The Installation ...

 
The first step is to install the module, the installation must be done as any other installation, either you can use Drush or Install it through Drupal's module administration page, in order to install it using Drush you just have to type the following commands in the shell on the Drupal installation path:
  1. > drush dl xmlsitemap
by typing that command you would be installing the XML Sitemap module, you can also try to install the module through the Drupal's module administration page, in order to do it, you must go to the module administration page and click the "install new module" link, then you can either download the module and upload it to Drupal or provide the FTP path to let Drupal download the module for you (this is the FTP path to install XML sitemap on Drupal 7: http://ftp.drupal.org/files/projects/xmlsitemap-7.x-2.0-rc2.tar.gz, the FTP paths are the download links in the module page), click the "Install" button and you will have installed the XML Sitemap module.
 

Enabling the proper sub-modules

 
The XML Sitemap module is based on multiple sub-modules that work together, in order to make it work, we have to enable the XML sitemap module along with the other modules, we have to select which of those modules should be active and which not, here is a possible list with all the sub-modules:
  • XML Sitemap; the main module, make sure to add the other modules because if not you will only see a sitemap with the link of the home page, just that.
  • XML Sitemap custom; this sub-module can let you add custom links to the sitemap.
  • XML Sitemap engines; this sub-module will upload the sitemap to the search engines automatically.
  • XML Sitemap internationalization; this sub-module enable the sitemaps on multi-lingual Drupal installations.
  • XML Sitemap menu; It enables the menu links to be in the sitemap.
  • XML Sitemap node; It enables the nodes (the content, content types and everything related) to be in the sitemap, do not forget to enable this sub-module, it is really important.
  • XML Sitemap taxonomy; this sub-module can add the taxonomy term links to the sitemap.
  • XML Sitemap user; it adds the user profile to the sitemap.
As you can see in the list above, although the XML Sitemap module is just one, there are many sub-modules with different task, however, there are key sub-modules that you should enable, for example, if you do not enable the XML Sitemap node sub-module, then the content of the whole sitemap is not going to be shown (it has no sense), if you have a multi-lingual Drupal installation and you do not activate the XML Sitemap internationalization sub-module then you are more likely to have only one sitemap with every link (with all the languages), it is really important that, at least, you activate the XML Sitemap node sub-module.
 
XML Sitemap sub-modules
The functionality of the XML Sitemap module is based on multiple sub-modules.
Attribution: 
 

How does this module works

 
Depending on the sub-modules that you have enabled, every group of content and all its children are going to have a new option identified as "XML Sitemap", normally, if a group of content is enabled all its children will be enabled as well, for example, the XML Sitemap menu sub-module adds the options to the menus and each menu link, if a menu is enabled, all its menu links will be enabled by default, the XML Sitemap taxonomy sub-module adds the options to the taxonomy term lists and each taxonomy term, if a taxonomy term list is enabled, then all its terms will be enabled by default, the XML Sitemap node sub-module adds the options to the content types and each node, if a content type is enabled, then all its nodes will be enabled by default. There are two options, the first one is the "Inclusion" option, this options lets the content be included in the sitemap, it has a default value set to "Excluded", once the content is included, the "priority" option may appear, it has a default value of "0.5", however, this value (as all the values) can be changed.
 

Adding the content to the sitemaps

Make sure to enable the XML Sitemap node sub-module in order to add the content to the sitemaps.
If you have the required modules available, you can add the content to the sitemaps (the nodes more specifically), in order to do it, you should set the options at the content types, you can enable the content type to be written in the sitemaps and set the priority for all that kind of content.
 
XML Sitemap - Content type
The content types are going to have a new option section, these option will be inherited by all its associated nodes.
Attribution: 
 
If you enable the content type, all the related content will be written in the sitemaps, however, you can still change the configuration of each node, so if you want every node to be sent but one node, you can enable the content type and disable the node.
 
XML Sitemap - Article
This is the new option section in every node, the nodes are excluded by default, you can either include its content type or just the node itself.
Attribution: 
 

Adding the menus (navigation) to the sitemaps

Make sure to enable the XML Sitemap menu sub-module in order to add the content to the sitemaps.
You can also add the menu links to the sitemaps, in order to do that, just do the same as described before, every menu (and all its links) in the Menu administration page of Drupal will have a new option, you can either include the whole menu in the sitemaps
 
XML Sitemap - Main menu
The menus can be added to the sitemap.
Attribution: 
 
or include just a single link,
 
XML Sitemap - Menu link
You can also add just a single link to the sitemaps.
Attribution: 
 
if you add the whole menu, all its links are going to be included too, you can change the options for each link if desired.
 

Adding the taxonomy term lists to the sitemaps

Make sure to enable the XML Sitemap taxonomy sub-module in order to add the content to the sitemaps.
The taxonomy term lists can also be included to the sitemaps, the procedure is just the same, you can include either the whole taxonomy term list
 
XML Sitemap - Taxonomy term list
Even the taxonomy term lists can be added to the sitemaps.
Attribution: 
 
or a single taxonomy term,
 
XML Sitemap - Taxonomy term
Attribution: 
 
if you include the whole taxonomy term list then all its taxonomy terms will be included by default, if not you have to include every single taxonomy term manually.
 

The Configurations

 
The configuration options of the XML Sitemap module (and all its modules) are located in the configuration options of Drupal, here you can add custom links (with the proper module previously enabled), customize the upload process to the search engines, rebuild the links of the sitemaps, and perform any other configuration activity related to this module.
 
XML Sitemap - Configuration
Attribution: 
 
You can add a custom link to the sitemaps in the "Custom Links" tap, in order to add a custom link, the supplied path must be accessible, additionally, it must be based on the URL of the website, this is for situation that an external webpage must be added within Drupal, for example, if I want to add a  webpage of a free software project in my website that I could not built in Drupal, I can still add the webpage by giving access to a specific path in my domain and adding that link to the sitemaps through this configuration panel.
XML Sitemap - Custom links
You can add custom links of external webpages in your domain to the sitemaps.
Attribution: 
The XML Sitemap module has the capability to upload the sitemaps to the search engines, you can customize how often the sitemaps should be uploaded and which search engines should receive the sitemap, however, there are some details to be warned of, first you are more likely to need the "Site verification" module in order to verify the ownership with the search engines, additionally, you must be sure that the Drupal cron runs regularly.
 
XML Sitemap - Search Engine Submission
You can customize how often the sitemaps are submitted to the search engines.
Attribution: 

About me

About the author
Miguel Rodríguez is a freelance developer from Caracas - Venezuela. He is a persistent and goal-oriented person who tries to make the best use of the resources. He is positive, proactive and motivated enough to set a goal with the intention to fulfill it. Find more about him .