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:
- Using a CMS plugin (easiest—5 minutes)
- Using an online generator (easy—10 minutes)
- 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.)
Method 1: Using a CMS Plugin (Recommended for Most People)
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:
- Install Yoast SEO:
- Go to Plugins → Add New
- Search for "Yoast SEO"
-
Click "Install Now" then "Activate"
-
Enable XML sitemaps:
- Go to SEO → General
- Click the "Features" tab
-
Make sure "XML sitemaps" is toggled ON (it's on by default)
-
View your sitemap:
- Click the "?" icon next to "XML sitemaps"
- Click "See the XML sitemap"
- 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:
- Install Rank Math:
- Go to Plugins → Add New
- Search for "Rank Math"
- Install and activate
-
Run through the setup wizard
-
Configure sitemap settings:
- Go to Rank Math → Sitemap Settings
-
Your sitemap is automatically enabled at
/sitemap_index.xml -
Customize what's included:
- Toggle content types on/off
- Set the number of entries per sitemap
- 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:
- Go to Marketing & SEO → SEO Tools
- Click "Get Found on Google"
- 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:
-
Go to XML-Sitemaps.com
-
Enter your website URL:
- Type your full domain (e.g.,
https://example.com) -
Click "Start"
-
Wait for the crawl:
- The tool will crawl your site (can take a few minutes)
-
It follows links to discover all pages
-
Download the sitemap:
- Click "View Sitemap Details"
-
Download
sitemap.xml -
Upload to your website:
- Use FTP or your hosting file manager
- Upload
sitemap.xmlto 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:
- Download and install:
- Get it from screamingfrog.co.uk
-
Free version works for up to 500 URLs
-
Crawl your site:
- Enter your website URL
- Click "Start"
-
Wait for the crawl to complete
-
Generate the sitemap:
- Go to Sitemaps → XML Sitemap
- Configure settings (include images, videos, etc.)
-
Click "Next" then "Export"
-
Upload to your website:
- Upload the generated
sitemap.xmlto 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
noindexmeta 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
- Log into Google Search Console
- Select your property
- Go to Sitemaps (in the left sidebar)
- Enter your sitemap URL (just the path:
sitemap.xml) - 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
- Log into Bing Webmaster Tools
- Select your site
- Go to Sitemaps
- Enter your sitemap URL
- 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
- XML Sitemap Validator
- Search Console Sitemap Tester (submit and check for errors)
Manual Checks
- Open in browser: Should display XML (not an error page)
- Check XML syntax: Should start with
<?xml version="1.0"?> - Verify URLs: Click a few to make sure they work
- Check file size: Should be under 50MB
- 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:
- Submit to search engines - Google Search Console and Bing Webmaster Tools
- Monitor for errors - Check weekly for issues
- Keep it updated - Regenerate when content changes
- Optimize for SEO - Learn about crawl budget optimization
- 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.