All posts
How-To Guides

How to Create an XML Sitemap (Step-by-Step Guide for Any Website)

A practical walkthrough for generating an XML sitemap — whether you're on WordPress, Shopify, a custom framework, or a plain HTML site.

June 20, 2026·6 min read

An XML sitemap is one of the simplest technical SEO improvements you can make. It takes about 15 minutes to get right, and once it's in place you never have to think about it again — search engines will find your pages faster, and you'll have a clear map of everything on your site. This guide covers every method, from one-click plugins to writing the file manually.

What Goes in an XML Sitemap

Before you generate anything, know what to include and what to leave out.

Include: every page you want indexed — homepage, product pages, blog posts, landing pages, category pages with real content.

Exclude: login and account pages, checkout flows, admin URLs, paginated search results, thin tag archives, pages with a noindex directive, and redirect sources — always list the final destination URL, never the redirect.

One important fact that surprises many people: Google officially ignores the <priority> and <changefreq> tags — they were widely abused and Google stopped using them. The tag that actually matters is <lastmod>, but only if it's genuinely accurate and reflects real content changes, not just a timestamp you refresh on every crawl.

Method 1 — WordPress (Yoast SEO or Rank Math)

If your site runs on WordPress, you almost certainly don't need a separate sitemap tool. Yoast SEO and Rank Math both generate and maintain your sitemap automatically.

Yoast SEO: Go to SEO → General → Features and confirm that XML sitemaps is switched on. Your sitemap index lives at /sitemap_index.xml. Yoast automatically splits it by content type (posts, pages, categories) and updates it when you publish or delete content.

Rank Math: Go to Rank Math → Sitemap Settings. Your sitemap is also at /sitemap_index.xml and updates automatically.

WordPress Core (no plugin): WordPress ships with a built-in sitemap since version 5.5, available at /wp-sitemap.xml. It's functional but more basic — it includes all public post types and taxonomies but has fewer options for fine-tuning what's included.

Method 2 — Shopify

Shopify generates your sitemap automatically at yourdomain.com/sitemap.xml. It's actually a sitemap index that points to separate sitemaps for products, collections, pages, and blog posts. You can't edit the sitemap directly, but you can control what appears in it by managing which pages are set to be indexed in your theme settings. There's nothing to install or configure — just submit the URL to Google Search Console.

Method 3 — Next.js, Nuxt, and Custom Frameworks

Modern JavaScript frameworks can generate sitemaps programmatically from your route definitions.

Next.js App Router: Create app/sitemap.ts and export a function that returns your URL list. Next.js serves it at /sitemap.xml automatically.

// app/sitemap.ts
import type { MetadataRoute } from 'next';

export default function sitemap(): MetadataRoute.Sitemap {
  return [
    { url: 'https://example.com', lastModified: new Date() },
    { url: 'https://example.com/about', lastModified: new Date() },
  ];
}

For dynamic pages (blog posts, product pages), fetch the slugs from your database or CMS inside the same function and map them to URL entries.

Method 4 — Crawl and Generate

If you can't modify your site's code (a legacy system, a third-party platform, or a static site with no build pipeline), the easiest option is to crawl your site and export the XML. A crawler visits every public page on your site by following links, then produces a valid sitemap from what it found.

This approach also gives you a health report showing which URLs return errors — so you can clean up your sitemap before submitting it, rather than handing Google a list of 404s to crawl.

The Minimal Valid Sitemap Format

If you want to create one by hand for a small site, this is all you need:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-06-01</lastmod>
  </url>
  <url>
    <loc>https://example.com/about</loc>
    <lastmod>2026-05-15</lastmod>
  </url>
</urlset>

Save it as sitemap.xml, upload it to the root of your web server, and verify it's accessible at https://yourdomain.com/sitemap.xml before submitting.

After You Generate the Sitemap

  1. Validate the XML — open the sitemap URL in your browser and check that it renders as a clean XML tree with no errors. A malformed XML file will cause a parse error in Search Console.
  2. Check for 404s in your URL list — every URL in your sitemap should return HTTP 200. Any 404s or redirects should be fixed or removed before you submit.
  3. Submit to Google Search Console — go to Index → Sitemaps, enter your sitemap URL, and click Submit.
  4. Submit to Bing Webmaster Tools — Bing's crawler doesn't share sitemap data with Google, so submit separately at bing.com/webmasters.
  5. Reference it in robots.txt — add Sitemap: https://yourdomain.com/sitemap.xml to your robots.txt so any crawler that reads robots.txt first will find your sitemap automatically.

Try it free

Generate and check your sitemap in minutes

Crawl up to 2,000 URLs for free — no credit card required. See your health score and download your sitemap XML instantly.

Generate your sitemap →