Developers

WP-CLI Commands

Published

Super Speedy Sitemaps adds a wp sssm command group to WP-CLI. It builds and caches every sitemap ahead of crawlers, reports the plugin’s state, clears the cache and reads the Sitemap Log, so all of it can be scripted, run over SSH or scheduled with cron.

Available since 1.16.0.

CommandWhat it does
wp sssm statusThe sitemap address, caching, cache folder and size, failure mode, Sitemap Log size, which SEO plugins’ noindex settings are applied, and any other sitemap generator
wp sssm warmBuilds and caches the sitemap index and every sitemap it lists
wp sssm flushDeletes every cached sitemap file, like Flush Cache
wp sssm logLists recent Sitemap Log entries
wp sssm clear-logEmpties the Sitemap Log, like Clear Log

Run them from the WordPress folder, or add --path=/path/to/wordpress. On a multisite network, add --url= with the site’s address.

Build every sitemap ahead of crawlers

wp sssm warm

warm requests the sitemap index from the site itself, then each sitemap the index lists, through the same code a search engine’s request runs. Every sitemap that is not already cached is built and saved, so the next crawler gets a file from disk instead of waiting for a build. It prints one row per sitemap:

sitemap                     status       urls  kb   seconds
sitemap.xml                 200          10    2.1  0.05
post_part1.xml              200          15    3.6  0.04
post_product.xml            200          3     1.2  0.04
taxonomy_product_tag.xml    404 (empty)              0.04
Success: 11 sitemaps requested.

A 404 (empty) row is an enabled sitemap with nothing in it, such as a taxonomy with no terms. It is not an error.

Add --regenerate to rebuild every sitemap, including those already cached:

wp sssm warm --regenerate

This is the same as the Regenerate button: cached files are treated as out of date and kept as last good copies until each new build replaces them. --timeout=<seconds> sets how long to wait for each sitemap (default 300).

warm needs Advanced Options > Sitemap Cache > Enable caching on; without it each sitemap is built and thrown away, and the command says so.

0 * * * * cd /var/www/example.com && wp sssm warm --quiet

Builds run by warm appear in the Sitemap Log with Requested by set to WP-CLI. If any sitemap fails, warm exits with an error and points to wp sssm log --problems.

warm fetches the site over HTTP from the server it runs on. If the site is behind HTTP authentication, or its address does not resolve on the server, the requests fail and warm prints the HTTP status or the connection error for each one.

Check the plugin’s state

wp sssm status
wp sssm status --format=json

other_generators lists any plugin also publishing a sitemap, the same list as the warning on the XML Sitemaps tab. See Running Alongside Other Sitemap Generators.

Read the Sitemap Log

wp sssm log
wp sssm log --problems
wp sssm log --limit=200 --format=csv > sitemap-log.csv
wp sssm log --fields=logged_at,sitemap,outcome,url_count,duration_ms

--problems shows only failed and empty builds. --limit defaults to 50; --format takes table, csv, json or yaml. The columns are those of the Sitemap Log tab: logged_at (UTC), sitemap, outcome, served, url_count, bytes, gzip_bytes, duration_ms, query_count, peak_memory, request_trigger and message.

Clear the cache or the log

wp sssm flush
wp sssm clear-log

Further reading

What each column and result means.
Caching, the last good copy and 503s.
Filters for everything else.

Written for Super Speedy Sitemaps 1.16.0.

Comments