How to generate a sitemap for a static WordPress site

Sitemap for WordPress static site

I’m using WordPress with the Simply Static plugin to generate the static version of my site and the Yoast plugin to generate the sitemap, a map of the site.

Simply Static doesn’t fetch the sitemap from the site, so you don’t have one to upload to the Google search console. But I solved this problem. At least on Linux.

But, first, let me explain why you need a map of your site.

Why you need a map of your site

From what I have read, having  a map of your site helps Google crawl it. Google can read all the links from the map and go to fetch them. Even if you forgot to link some page from another page, the map of the site helps Google find it.

How to control Yoast sitemap generation

If you want to access to the XML Sitemaps settings on Yoast (SEO tab in the WordPress dashboard) you first have to enable Advanced settings pages from the Features tab in the SEO Yoast settings.

Then, after opening the XML Sitemaps tab in the dashboard, you’ll see that the map generation is enabled. From the tabs in XML Sitemaps you can enable or disable the generation of the XML map for posts or pages, categories or tags, and choose the maximum number of items for each map.

Yoast XML sitemaps settings
Yoast XML sitemaps settings

The Linux Bash script

To generate the sitemap run the script which follows in the directory where you have your WordPress site files, it will fetch the sitemap generated from Yoast and rewrite the links to reflect the real site (I have mine installed as localhost)

Use the script at your own risk.

You have to change the site variable to reflect the host and root of your WordPress site and to replace the strings in the sed line with your values. Slashes in the sed line must be escaped with a backslash.

In my case, as I said, I had to replace localhost/wp, where the dynamic WordPress site is hosted, with, where the static site is.

After having generated the sitemap files you can upload them on the Google Search Console and be sure that all your files are crawled.

Other sitemap generators

Another plugin which can create a sitemap for WordPress is Google XML Sitemaps, but I used Yoast because it has other useful features for Search Engine Optimization (SEO).

You can find the complete list of the plugins I’m using here