Tutorial 13 min read

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

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

So you need to create an XML sitemap. Maybe you're launching a new website, or you discovered your current sitemap is broken, or you're building a custom site from scratch.

Whatever the reason, I've got you covered.

The good news: Creating a sitemap is easier than you think. For most websites, it's literally a one-click process. For custom sites, it's a bit more involved, but still totally doable.

In this guide, I'll show you three ways to create a sitemap:

  1. Using a CMS plugin (easiest—5 minutes)
  2. Using an online generator (easy—10 minutes)
  3. Writing custom code (advanced—30+ minutes)

Pick the method that matches your technical comfort level and website setup.

Before You Start: What You'll Need

Before creating your sitemap, gather this information:

  • Your website's domain (e.g., https://example.com)
  • Access to your website (admin panel, FTP, or hosting control panel)
  • A list of pages you want indexed (or access to your CMS database)
  • Google Search Console access (for submitting the sitemap after creation)

Quick terminology check:

  • URL: A specific page address (e.g., https://example.com/about)
  • XML: The format sitemaps are written in (don't worry, you won't write it by hand)
  • CMS: Content Management System (WordPress, Shopify, etc.)

If you're using WordPress, Shopify, Wix, or another popular platform, this is the easiest method. These platforms have plugins or built-in features that automatically generate and update your sitemap.

WordPress: Using Yoast SEO

Yoast SEO is the most popular WordPress SEO plugin, and it includes automatic sitemap generation.

Steps:

  1. Install Yoast SEO:
  2. Go to Plugins → Add New
  3. Search for "Yoast SEO"
  4. Click "Install Now" then "Activate"

  5. Enable XML sitemaps:

  6. Go to SEO → General
  7. Click the "Features" tab
  8. Make sure "XML sitemaps" is toggled ON (it's on by default)

  9. View your sitemap:

  10. Click the "?" icon next to "XML sitemaps"
  11. Click "See the XML sitemap"
  12. Your sitemap is now live at /sitemap_index.xml

That's it! Yoast automatically:

  • Generates sitemaps for posts, pages, categories, and tags
  • Updates the sitemap when you publish/update content
  • Excludes noindex pages and private content
  • Splits large sitemaps into multiple files

Customization options:

  • Go to SEO → Search Appearance
  • Click each content type tab (Posts, Pages, etc.)
  • Toggle "Show [content type] in search results" to include/exclude from sitemap

WordPress: Using Rank Math

Rank Math is another excellent SEO plugin with powerful sitemap features.

Step-by-step:

  1. Install Rank Math:
  2. Go to Plugins → Add New
  3. Search for "Rank Math"
  4. Install and activate
  5. Run through the setup wizard

  6. Configure sitemap settings:

  7. Go to Rank Math → Sitemap Settings
  8. Your sitemap is automatically enabled at /sitemap_index.xml

  9. Customize what's included:

  10. Toggle content types on/off
  11. Set the number of entries per sitemap
  12. Exclude specific posts/pages

Rank Math advantages:

  • More granular control than Yoast
  • Can include/exclude individual posts
  • Shows estimated sitemap size
  • Includes images automatically

WordPress: Core Sitemap (WordPress 5.5+)

WordPress 5.5 introduced a basic built-in sitemap. It's not as feature-rich as plugins, but it works.

How to access it:

  • Your sitemap is automatically at /wp-sitemap.xml
  • No setup required!

Limitations:

  • Can't customize what's included
  • No image sitemaps
  • No video sitemaps
  • Basic functionality only

When to use it: If you have a simple site and don't want to install a plugin.

Shopify: Automatic Sitemaps

Shopify generates sitemaps automatically for all stores. You don't need to do anything.

Your sitemap is at:

https://yourstore.myshopify.com/sitemap.xml

Or with a custom domain:

https://yourdomain.com/sitemap.xml

What's included:

  • All products
  • All collections
  • All pages
  • All blog posts

Limitations:

  • You can't customize what's included
  • You can't exclude specific pages
  • It's all automatic (which is usually fine!)

Wix: Automatic Sitemaps

Wix also generates sitemaps automatically.

Your sitemap is at:

https://yourdomain.com/sitemap.xml

To verify:

  1. Go to Marketing & SEO → SEO Tools
  2. Click "Get Found on Google"
  3. Your sitemap URL is listed

Note: Wix sitemaps are always enabled and can't be customized much.

Squarespace: Automatic Sitemaps

Squarespace generates sitemaps automatically.

Your sitemap is at:

https://yourdomain.com/sitemap.xml

What's included:

  • All pages
  • All blog posts
  • All gallery images
  • All products (if using Commerce)

Customization: Very limited. Squarespace handles it all automatically.

Method 2: Using an Online Sitemap Generator

If you have a static HTML site or a custom CMS without sitemap support, use an online generator.

XML-Sitemaps.com (Free for Small Sites)

Best for: Sites with under 500 pages

Step-by-step:

  1. Go to XML-Sitemaps.com

  2. Enter your website URL:

  3. Type your full domain (e.g., https://example.com)
  4. Click "Start"

  5. Wait for the crawl:

  6. The tool will crawl your site (can take a few minutes)
  7. It follows links to discover all pages

  8. Download the sitemap:

  9. Click "View Sitemap Details"
  10. Download sitemap.xml

  11. Upload to your website:

  12. Use FTP or your hosting file manager
  13. Upload sitemap.xml to your website's root directory

Limitations:

  • Free version limited to 500 pages
  • Must manually re-generate when content changes
  • Doesn't automatically update

Screaming Frog SEO Spider (Free for 500 URLs)

Best for: SEO professionals and larger sites

Step-by-step:

  1. Download and install:
  2. Get it from screamingfrog.co.uk
  3. Free version works for up to 500 URLs

  4. Crawl your site:

  5. Enter your website URL
  6. Click "Start"
  7. Wait for the crawl to complete

  8. Generate the sitemap:

  9. Go to Sitemaps → XML Sitemap
  10. Configure settings (include images, videos, etc.)
  11. Click "Next" then "Export"

  12. Upload to your website:

  13. Upload the generated sitemap.xml to your root directory

Advantages:

  • Very powerful and customizable
  • Can include images, videos, hreflang
  • Shows errors and warnings
  • Great for auditing existing sitemaps

Sitebulb (Paid, but Powerful)

Best for: Professional SEO audits

Features:

  • Comprehensive site crawling
  • Automatic sitemap generation
  • Error detection and recommendations
  • Visual reports

Pricing: Starts at $35/month

Method 3: Creating a Sitemap Manually (Custom Code)

For developers building custom sites, you'll want to generate sitemaps programmatically.

Option A: Static XML File (Simple Sites)

If you have a small, rarely-changing site, you can create a sitemap manually.

Example sitemap.xml:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2025-11-26</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>https://example.com/about</loc>
    <lastmod>2025-11-20</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.8</priority>
  </url>
  <url>
    <loc>https://example.com/contact</loc>
    <lastmod>2025-11-15</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.5</priority>
  </url>
</urlset>

Required elements:

  • <urlset>: Wrapper for all URLs
  • <url>: Container for each page
  • <loc>: The page URL (required)

Optional elements:

  • <lastmod>: Last modified date (YYYY-MM-DD format)
  • <changefreq>: How often it changes (daily, weekly, monthly, yearly)
  • <priority>: Importance (0.0 to 1.0)

Note: Google mostly ignores changefreq and priority, but they don't hurt.

Option B: Python Script (Dynamic Sites)

For sites with databases or frequently changing content, generate sitemaps programmatically.

Python example using Flask:

from flask import Flask, Response
from datetime import datetime

app = Flask(__name__)

# Your pages (in real app, fetch from database)
pages = [
    {'url': '/', 'lastmod': '2025-11-26', 'priority': '1.0'},
    {'url': '/about', 'lastmod': '2025-11-20', 'priority': '0.8'},
    {'url': '/blog', 'lastmod': '2025-11-25', 'priority': '0.9'},
]

@app.route('/sitemap.xml')
def sitemap():
    xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
    xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'

    for page in pages:
        xml += '  <url>\n'
        xml += f'    <loc>https://example.com{page["url"]}</loc>\n'
        xml += f'    <lastmod>{page["lastmod"]}</lastmod>\n'
        xml += f'    <priority>{page["priority"]}</priority>\n'
        xml += '  </url>\n'

    xml += '</urlset>'

    return Response(xml, mimetype='application/xml')

if __name__ == '__main__':
    app.run()

For a database-driven site:

from flask import Flask, Response
from datetime import datetime
import sqlite3

app = Flask(__name__)

@app.route('/sitemap.xml')
def sitemap():
    # Connect to database
    conn = sqlite3.connect('blog.db')
    cursor = conn.cursor()

    # Fetch all published posts
    cursor.execute('''
        SELECT slug, updated_at 
        FROM posts 
        WHERE status = 'published'
        ORDER BY updated_at DESC
    ''')
    posts = cursor.fetchall()

    # Build XML
    xml = '<?xml version="1.0" encoding="UTF-8"?>\n'
    xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'

    # Add homepage
    xml += '  <url>\n'
    xml += '    <loc>https://example.com/</loc>\n'
    xml += f'    <lastmod>{datetime.now().strftime("%Y-%m-%d")}</lastmod>\n'
    xml += '    <priority>1.0</priority>\n'
    xml += '  </url>\n'

    # Add blog posts
    for slug, updated_at in posts:
        xml += '  <url>\n'
        xml += f'    <loc>https://example.com/blog/{slug}</loc>\n'
        xml += f'    <lastmod>{updated_at}</lastmod>\n'
        xml += '    <priority>0.8</priority>\n'
        xml += '  </url>\n'

    xml += '</urlset>'

    conn.close()
    return Response(xml, mimetype='application/xml')

Option C: Node.js Script

Using Express:

const express = require('express');
const app = express();

// Your pages (fetch from database in real app)
const pages = [
  { url: '/', lastmod: '2025-11-26', priority: '1.0' },
  { url: '/about', lastmod: '2025-11-20', priority: '0.8' },
  { url: '/blog', lastmod: '2025-11-25', priority: '0.9' },
];

app.get('/sitemap.xml', (req, res) => {
  let xml = '<?xml version="1.0" encoding="UTF-8"?>\n';
  xml += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';

  pages.forEach(page => {
    xml += '  <url>\n';
    xml += `    <loc>https://example.com${page.url}</loc>\n`;
    xml += `    <lastmod>${page.lastmod}</lastmod>\n`;
    xml += `    <priority>${page.priority}</priority>\n`;
    xml += '  </url>\n';
  });

  xml += '</urlset>';

  res.header('Content-Type', 'application/xml');
  res.send(xml);
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Option D: PHP Script

For PHP sites:

<?php
header('Content-Type: application/xml; charset=utf-8');

// Your pages (fetch from database in real app)
$pages = [
    ['url' => '/', 'lastmod' => '2025-11-26', 'priority' => '1.0'],
    ['url' => '/about', 'lastmod' => '2025-11-20', 'priority' => '0.8'],
    ['url' => '/blog', 'lastmod' => '2025-11-25', 'priority' => '0.9'],
];

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

foreach ($pages as $page) {
    echo '  <url>' . "\n";
    echo '    <loc>https://example.com' . $page['url'] . '</loc>' . "\n";
    echo '    <lastmod>' . $page['lastmod'] . '</lastmod>' . "\n";
    echo '    <priority>' . $page['priority'] . '</priority>' . "\n";
    echo '  </url>' . "\n";
}

echo '</urlset>';
?>

Best Practices for Creating Sitemaps

1. Only Include Indexable URLs

Include:

  • Published pages and posts
  • Important category/tag pages
  • Product pages
  • Public resources

Don't include:

  • Pages with noindex meta tags
  • URLs blocked by robots.txt
  • Duplicate content
  • Paginated pages (use canonical tags instead)
  • Admin pages
  • Thank you pages
  • 404 error pages

2. Use Absolute URLs

Good:

<loc>https://example.com/about</loc>

Bad:

<loc>/about</loc>
<loc>example.com/about</loc>

Always include the full protocol (https://) and domain.

3. Keep It Under the Limits

Sitemap limits:

  • Maximum 50,000 URLs per file
  • Maximum 50MB uncompressed

If you exceed these, create a sitemap index:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://example.com/sitemap-posts.xml</loc>
    <lastmod>2025-11-26</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-pages.xml</loc>
    <lastmod>2025-11-25</lastmod>
  </sitemap>
</sitemapindex>

4. Use Accurate lastmod Dates

The <lastmod> tag tells Google when a page was last updated. Use the actual modification date, not the current date. (See our lastmod guide for details.)

Format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS+00:00

Example:

<lastmod>2025-11-26</lastmod>
<lastmod>2025-11-26T14:30:00+00:00</lastmod>

5. Compress Large Sitemaps

If your sitemap is large, compress it with gzip:

gzip sitemap.xml

This creates sitemap.xml.gz. Google can read gzipped sitemaps, and they load faster.

6. Update Automatically

For dynamic sites: Generate the sitemap on-the-fly from your database For static sites: Regenerate the sitemap whenever content changes For CMS sites: Use a plugin that auto-updates

Never: Let your sitemap get stale with old/deleted pages

After Creating Your Sitemap

Step 1: Upload to Your Website

Place your sitemap at the root of your domain:

https://yourdomain.com/sitemap.xml

How to upload:

  • FTP: Use FileZilla or another FTP client
  • Hosting control panel: Use the file manager
  • CMS: Plugin handles this automatically

Step 2: Add to robots.txt

Edit your robots.txt file to include:

User-agent: *
Disallow: /admin/

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

This tells all search engines where to find your sitemap.

Step 3: Submit to Google Search Console

  1. Log into Google Search Console
  2. Select your property
  3. Go to Sitemaps (in the left sidebar)
  4. Enter your sitemap URL (just the path: sitemap.xml)
  5. Click "Submit"

What to expect:

  • Google will fetch and process your sitemap
  • Check back in a few days to see how many URLs were discovered
  • Monitor for errors or warnings

Step 4: Submit to Bing Webmaster Tools

  1. Log into Bing Webmaster Tools
  2. Select your site
  3. Go to Sitemaps
  4. Enter your sitemap URL
  5. Click "Submit"

Step 5: Monitor for Errors

Check Google Search Console regularly for sitemap issues:

  • Couldn't fetch: Google can't access your sitemap
  • Submitted URL not found (404): URLs in your sitemap don't exist
  • Submitted URL marked 'noindex': Conflicting signals
  • Submitted URL blocked by robots.txt: Can't be crawled

Fix these issues as they appear to keep your sitemap healthy.

Testing Your Sitemap

Before submitting, validate your sitemap:

Online Validators

Manual Checks

  1. Open in browser: Should display XML (not an error page)
  2. Check XML syntax: Should start with <?xml version="1.0"?>
  3. Verify URLs: Click a few to make sure they work
  4. Check file size: Should be under 50MB
  5. Count URLs: Should be under 50,000

Use Our Tool

Visualize your sitemap with Sitemap Explorer to:

  • See your site structure as a tree
  • Identify broken links
  • Check for duplicate URLs
  • Verify all pages are included

Troubleshooting Common Issues

"My sitemap returns a 404 error"

Causes:

  • File not uploaded correctly
  • Wrong file permissions
  • Server configuration blocking .xml files

Fix: Re-upload the file, check permissions (should be 644), check your server config.

"Google says 'Couldn't fetch'"

Causes:

  • Server is down
  • Firewall blocking Googlebot
  • robots.txt blocking the sitemap

Fix: Test the URL in an incognito browser, check your firewall settings, verify robots.txt.

"Sitemap has too many URLs"

Fix: Split into multiple sitemaps and create a sitemap index.

"URLs in sitemap return 404"

Fix: Remove deleted pages from your sitemap or fix the broken URLs.

Next Steps

Now that you've created your sitemap:

  1. Submit to search engines - Google Search Console and Bing Webmaster Tools
  2. Monitor for errors - Check weekly for issues
  3. Keep it updated - Regenerate when content changes
  4. Optimize for SEO - Learn about crawl budget optimization
  5. Fix any errors - Use our Google Search Console error guide

Key Takeaways

  • CMS users: Use a plugin (Yoast, Rank Math) for automatic sitemap generation
  • Static sites: Use an online generator like XML-Sitemaps.com
  • Custom sites: Write a script to generate sitemaps from your database
  • Always: Submit to Google Search Console and add to robots.txt
  • Best practice: Keep sitemaps under 50,000 URLs and 50MB
  • Important: Only include indexable, canonical URLs

Remember: A sitemap is not a guarantee of indexing, but it makes it much more likely that Google will find and index your content.

Ready to see what your sitemap looks like? Explore it visually with our free sitemap visualization tool.

Ready to audit your sitemap?

Visualize your site structure, spot errors, and improve your SEO with our free tool.

Launch Sitemap Explorer