How to create an XML sitemap in WordPress

By Pablo Murad. Last updated

You usually do not have to create one. Since version 5.5, WordPress publishes an XML sitemap on its own at /wp-sitemap.xml. If you run Yoast SEO or Rank Math, the plugin replaces it with its own, at /sitemap_index.xml. Either way, open the address, check what is listed and submit that one URL to Google.

The sitemap WordPress already makes

WordPress core builds the file on request, so there is nothing to upload or update. Go to https://your-site.com/wp-sitemap.xml. You will see an index that points to separate sitemaps for posts, pages, other public post types, taxonomies such as categories and tags, and users. Each of those files lists up to 2,000 URLs by default, so a larger site gets several pages per type. The WordPress 5.5 announcement describes the feature and the filters that change it.

Two things stop it from showing up. The first is the "Discourage search engines from indexing this site" setting under Settings, Reading: while it is on, core does not publish the sitemap. The second is a plugin that takes over the job, which is the next section.

Yoast SEO and Rank Math

Both plugins publish their own index at /sitemap_index.xml and turn the core sitemap off, so /wp-sitemap.xml stops working once the plugin is active. They let you pick which post types and taxonomies are listed, and they leave out content you mark as noindex. Pick one source and submit only that one. Two competing sitemaps for the same pages make the Search Console report harder to read.

To use the core sitemap with no plugin sitemap, switch the plugin's sitemap feature off in its settings. To do the opposite and switch the core one off, add this line to your theme's functions.php or to a small plugin:

add_filter( 'wp_sitemaps_enabled', '__return_false' );

Make sure Google knows where it is

With WordPress core, the sitemap address is added to the virtual robots.txt that WordPress serves, unless you keep a physical robots.txt file in the site folder. In that case add the line yourself:

Sitemap: https://www.example.com/wp-sitemap.xml

Then submit the URL in the Sitemaps report. The guide to submitting a sitemap to Google Search Console has the steps and explains each status.

When a separate generator makes sense

The WordPress and plugin sitemaps are built from the database, not from what a visitor or crawler actually finds. A generator that crawls the site shows you the second picture. It is worth the extra step when:

  • The site mixes WordPress with other parts, such as a static folder, a landing page builder or a separate app on the same domain, and one sitemap should cover all of it.
  • You suspect the sitemap lists pages that redirect, return errors, are marked noindex or point to another canonical. A crawl lists only what returns 200 and can be indexed, and reports what it left out.
  • You want to compare what the plugin lists with what is really reachable through internal links, to find orphan pages.
  • The theme or a caching layer breaks the plugin sitemap and you need a clean file quickly.

If you go that route, upload the generated file to the site and submit it in place of the plugin sitemap, not in addition to it. The XML sitemap guide explains what the file should contain.

Check the result

  • Open the sitemap URL in a browser. You should see XML, not a 404 page or your theme.
  • Look for URLs you do not want in search results: tag archives, author pages, thin attachment pages.
  • Run the file through the free sitemap validator to check the format, the limits and the status of each URL.

Want to see what a crawl of your WordPress site lists?

Try the free generator