How to Create a Sitemap

Four practical methods to create a sitemap for your website: CMS plugins, generator tools, hand-coded XML, and programmatic generation. Step-by-step instructions for each approach.

You need a sitemap. Maybe you just launched a site and want Google to find it. Maybe you inherited a project and realized there's no sitemap in place. Maybe you have one but it's outdated and full of broken URLs. Whatever the reason, creating a sitemap is straightforward -- there are just a few different ways to do it, and the right approach depends on your setup.

Here are four methods, from easiest to most hands-on.

Method 1: Use a CMS Plugin

If your site runs on a CMS like WordPress, Shopify, or Drupal, this is the fastest path. Install a plugin, configure a few settings, and your sitemap generates automatically.

WordPress

1

Install a sitemap plugin

The most popular options are Yoast SEO and Rank Math. Go to Plugins > Add New, search for either one, and install it. Both include sitemap generation as part of their broader SEO feature set.

2

Enable the sitemap feature

In Yoast: Go to Yoast SEO > Settings > Site Features and make sure "XML sitemaps" is toggled on. In Rank Math: Go to Rank Math > Sitemap Settings and ensure it's enabled.

3

Configure what to include

Both plugins let you choose which post types and taxonomies to include. At minimum, include your pages and posts. Exclude author archives and tag pages unless they have real content value. Exclude any noindex pages.

4

Verify the sitemap

Visit yoursite.com/sitemap_index.xml (Yoast) or yoursite.com/sitemap_index.xml (Rank Math). You should see a sitemap index with links to individual sitemaps for each content type.

WordPress 5.5+ also includes a basic built-in sitemap at /wp-sitemap.xml, but the plugins offer far more control over what's included and how it's structured.

Shopify

Shopify generates a sitemap automatically. There's nothing to install. Your sitemap lives at yourstore.com/sitemap.xml and includes products, collections, blog posts, and pages. It updates whenever you add or remove content.

The catch: you can't customize what's included or excluded. If you need to remove specific pages from the sitemap, you'll need to use a third-party app or handle it through robots.txt.

Other Platforms

  • Squarespace: Automatic at /sitemap.xml. No configuration needed.
  • Wix: Automatic at /sitemap.xml. Limited customization.
  • Webflow: Automatic. You can toggle sitemap inclusion per page in the page settings.
  • Drupal: Install the Simple XML Sitemap module for full control.
  • Ghost: Automatic at /sitemap.xml.

Method 2: Use an Online Generator Tool

If you don't use a CMS or want a sitemap for a static site, online generators work well for sites under a few thousand pages.

1

Choose a generator

XML-Sitemaps.com is the most popular free option (up to 500 URLs). Screaming Frog is a desktop app that handles much larger sites (up to 500 URLs in the free version, unlimited in paid). Sitebulb is another solid desktop option.

2

Enter your URL

Paste your homepage URL into the tool. The generator will crawl your site by following links from the homepage outward.

3

Wait for the crawl

Small sites take seconds. Sites with thousands of pages can take minutes or even hours. The tool is visiting every discoverable page, so the time scales with your site size.

4

Review and download

Check the generated list of URLs. Remove anything that shouldn't be in the sitemap (admin pages, duplicate content, staging URLs). Download the XML file.

5

Upload to your server

Place the sitemap.xml file in your site's root directory so it's accessible at yoursite.com/sitemap.xml. How you do this depends on your hosting -- FTP, file manager, deployment pipeline, etc.

Online generators create a snapshot, not a living sitemap

The downloaded file is static. When you add new pages, you'll need to regenerate and re-upload the sitemap. For sites that change frequently, Methods 1, 3, or 4 are better long-term solutions.

Method 3: Write XML by Hand

For small sites that rarely change, writing a sitemap manually is completely reasonable. It's just an XML file with a specific structure.

1

Create the file

Create a file called sitemap.xml in your text editor. Start with the XML declaration and the root element:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

</urlset>
2

Add your URLs

For each page, add a <url> block with the full URL and an optional last-modified date:

<url>
  <loc>https://yoursite.com/</loc>
  <lastmod>2026-02-19</lastmod>
</url>
<url>
  <loc>https://yoursite.com/about</loc>
  <lastmod>2026-01-15</lastmod>
</url>
<url>
  <loc>https://yoursite.com/contact</loc>
  <lastmod>2026-01-15</lastmod>
</url>
3

Validate the XML

Make sure the file is well-formed XML. Common mistakes: forgetting to close tags, using unescaped ampersands in URLs (use &amp; instead of &), and omitting the namespace declaration.

4

Upload to your root directory

Place sitemap.xml at the root of your domain so it's accessible at yoursite.com/sitemap.xml.

Hand-coding works for 5-20 pages. Beyond that, you're introducing unnecessary human error and maintenance burden. Use a generator or programmatic approach instead.

Validate your hand-coded sitemap

Check your XML sitemap for syntax errors, encoding issues, and protocol compliance before submitting it to search engines.

Method 4: Generate Programmatically

If you're building a custom site with a framework like Next.js, Gatsby, Django, Rails, or Laravel, you can generate your sitemap as part of your build or on each request.

Next.js Example

Next.js 13+ has built-in sitemap support. Create a file at app/sitemap.ts:

import { MetadataRoute } from 'next'

export default function sitemap(): MetadataRoute.Sitemap {
  return [
    {
      url: 'https://yoursite.com',
      lastModified: new Date(),
      changeFrequency: 'weekly',
      priority: 1,
    },
    {
      url: 'https://yoursite.com/about',
      lastModified: new Date('2026-01-15'),
      changeFrequency: 'monthly',
      priority: 0.8,
    },
  ]
}

For dynamic routes, fetch URLs from your database:

import { MetadataRoute } from 'next'
import { getAllPosts } from '@/lib/posts'

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const posts = await getAllPosts()

  const postUrls = posts.map((post) => ({
    url: `https://yoursite.com/blog/${post.slug}`,
    lastModified: post.updatedAt,
  }))

  return [
    { url: 'https://yoursite.com', lastModified: new Date() },
    { url: 'https://yoursite.com/about', lastModified: new Date('2026-01-15') },
    ...postUrls,
  ]
}

Node.js with the sitemap Package

npm install sitemap
const { SitemapStream, streamToPromise } = require('sitemap')
const { createWriteStream } = require('fs')

const sitemap = new SitemapStream({ hostname: 'https://yoursite.com' })
const writeStream = createWriteStream('./public/sitemap.xml')

sitemap.pipe(writeStream)
sitemap.write({ url: '/', lastmod: '2026-02-19', changefreq: 'weekly' })
sitemap.write({ url: '/about', lastmod: '2026-01-15', changefreq: 'monthly' })
sitemap.write({ url: '/blog', lastmod: '2026-02-18', changefreq: 'daily' })
sitemap.end()

Django

Django has built-in sitemap support:

# sitemaps.py
from django.contrib.sitemaps import Sitemap
from .models import BlogPost

class BlogSitemap(Sitemap):
    changefreq = "weekly"
    priority = 0.8

    def items(self):
        return BlogPost.objects.filter(status='published')

    def lastmod(self, obj):
        return obj.updated_at

    def location(self, obj):
        return f'/blog/{obj.slug}'

After Creating Your Sitemap: Submit It

Creating the sitemap is half the job. You also need to tell search engines where to find it.

1

Add it to robots.txt

Add this line to your robots.txt file:

Sitemap: https://yoursite.com/sitemap.xml

This is the universal method. Every major search engine checks robots.txt for sitemap declarations.

2

Submit to Google Search Console

Log into Google Search Console, go to Sitemaps in the left sidebar, enter your sitemap URL, and click Submit. Google will fetch and process it, then report any issues.

3

Submit to Bing Webmaster Tools

Similar process: log into Bing Webmaster Tools, go to Sitemaps, and submit the URL. Bing also reads your robots.txt declaration.

You only need to submit once

After the initial submission, search engines will periodically re-fetch your sitemap on their own. You don't need to resubmit every time it changes -- but if you make major structural changes, a re-submission can speed up re-crawling.

Which Method Should You Use?

MethodBest ForEffortStays Updated
CMS pluginWordPress, Shopify, Drupal5 minutesAutomatic
Online generatorStatic sites, one-off needs10-30 minutesManual re-generation
Hand-coded XMLTiny sites (under 20 pages)15-30 minutesManual editing
ProgrammaticCustom apps, large dynamic sites1-4 hours initialAutomatic

If you're using a CMS, start with Method 1. If you're building a custom app, jump to Method 4. Methods 2 and 3 are for specific situations where the other options don't apply.

The most important thing is that your sitemap exists, is accurate, and stays current. How you get there matters less than the fact that you get there.


The best sitemap is one that exists. The second best is one that's accurate. Start with any method and improve from there.

Validate your XML sitemap

Check your sitemap for errors, broken URLs, and indexing issues. Free instant validation.