How to Create an XML Sitemap for SEO: A Step-by-Step Guide
If you're trying to figure out how to create an XML sitemap for SEO, you're in the right place. An XML sitemap is one of those foundational SEO elements that search engines genuinely rely on to discover, crawl, and index your pages efficiently. Whether you're running a brand-new website or auditing an existing one, getting your sitemap right can directly influence how quickly your content shows up in search results — and which pages get indexed at all. This guide walks you through the entire process, from understanding what goes into a proper XML sitemap to submitting it to Google and Bing.
What Is an XML Sitemap and Why Does It Matter for SEO
An XML sitemap is a structured file — written in XML format — that lists the URLs on your website along with optional metadata like last modification dates, update frequency, and priority levels. It's essentially a roadmap you hand to search engine crawlers so they don't have to rely entirely on link discovery to find your pages.
Here's why it matters:
- Faster indexing: New pages get discovered and indexed more quickly when they're listed in a sitemap rather than waiting to be found through internal links.
- Deep page coverage: Pages buried deep in your site architecture or with few internal links pointing to them might never get crawled without a sitemap.
- Crawl budget efficiency: For large sites, a well-organized sitemap helps search engines spend their crawl budget on the pages that matter most.
- Canonical clarity: Sitemaps help reinforce which version of a URL is the canonical one, reducing duplicate content confusion.
Google has stated publicly that sitemaps are especially useful for large sites (over 500 pages), new sites with few backlinks, and sites with rich media content. But honestly, every site benefits from having one.
Understanding the XML Sitemap Format
Before you create anything, it helps to understand what a valid XML sitemap actually looks like. Here's a minimal, well-formed example:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/</loc>
<lastmod>2024-11-01</lastmod>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
<url>
<loc>https://www.example.com/about/</loc>
<lastmod>2024-10-15</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://www.example.com/blog/how-to-do-something/</loc>
<lastmod>2024-11-05</lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>
</urlset>
Key XML Sitemap Tags Explained
| Tag | Required | Description |
|---|---|---|
<loc> |
Yes | The full URL of the page (must include https://) |
<lastmod> |
No | Date the page was last modified (ISO 8601 format: YYYY-MM-DD) |
<changefreq> |
No | How often the page is likely to change (always, hourly, daily, weekly, monthly, yearly, never) |
<priority> |
No | Relative importance from 0.0 to 1.0 (default is 0.5) |
Important note: While changefreq and priority are valid tags, Google has stated they largely ignore them. Focus your energy on keeping <loc> accurate and <lastmod> up to date — those two carry the most weight.
How to Create an XML Sitemap for SEO: Step-by-Step Methods
There are several ways to create an XML sitemap depending on your technical comfort level and the platform your site runs on. Let's go through each one.
Method 1: Use OpDeck's Sitemap Generator (Fastest Option)
If you want to skip the manual work entirely, the Sitemap Generator from OpDeck is one of the quickest ways to produce a clean, SEO-ready XML sitemap. You simply enter your website's URL, and the tool crawls your site and outputs a properly formatted sitemap file you can download and deploy immediately.
This approach is ideal when:
- You don't have access to your CMS's sitemap plugin
- You're auditing a client's site and need a sitemap fast
- You want to verify that your existing sitemap matches what's actually on your site
- You're working with a static HTML site without a CMS
The generator handles the XML structure, URL encoding, and formatting automatically — so you don't have to worry about syntax errors that would cause Google Search Console to reject your file.
Method 2: Generate a Sitemap in WordPress
WordPress is the most common CMS, and there are a few solid options here.
Using Yoast SEO:
- Install and activate the Yoast SEO plugin
- Go to SEO → General → Features
- Make sure the XML sitemaps toggle is on
- Click the ? icon next to XML sitemaps and then "See the XML sitemap" to view your sitemap
- Your sitemap index will be available at
https://yourdomain.com/sitemap_index.xml
Using Rank Math:
- Install and activate Rank Math
- Navigate to Rank Math → Sitemap Settings
- Configure which post types and taxonomies to include
- Your sitemap will be at
https://yourdomain.com/sitemap_index.xml
Using All in One SEO:
- Go to All in One SEO → Sitemaps
- Enable the sitemap and configure your settings
- Your sitemap will be at
https://yourdomain.com/sitemap.xml
WordPress plugins generate sitemaps dynamically, meaning they update automatically as you publish or update content. This is the preferred approach for most WordPress sites.
Method 3: Create an XML Sitemap Manually
For small static sites (under 50 pages), creating a sitemap manually is completely viable. Here's how to do it from scratch:
Step 1: Create a new file called sitemap.xml
Open a text editor (VS Code, Sublime Text, Notepad++) and start with the XML declaration and namespace:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Step 2: Add each URL as a <url> block
<url>
<loc>https://www.yoursite.com/page-name/</loc>
<lastmod>2024-11-10</lastmod>
<priority>0.8</priority>
</url>
Step 3: Close the <urlset> tag
</urlset>
Step 4: Validate your XML
Before uploading, paste your file into an XML validator like xmlvalidation.com or use your browser — if the file opens without errors, it's well-formed.
Step 5: Upload to your root directory
Place sitemap.xml in your website's root directory so it's accessible at https://www.yoursite.com/sitemap.xml.
Method 4: Generate a Sitemap with Python (For Developers)
If you're managing a larger site or need automation, here's a simple Python script using the requests and xml.etree.ElementTree libraries:
import xml.etree.ElementTree as ET
from datetime import date
urls = [
"https://www.example.com/",
"https://www.example.com/about/",
"https://www.example.com/services/",
"https://www.example.com/contact/",
"https://www.example.com/blog/",
]
root = ET.Element("urlset")
root.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
for url in urls:
url_element = ET.SubElement(root, "url")
loc = ET.SubElement(url_element, "loc")
loc.text = url
lastmod = ET.SubElement(url_element, "lastmod")
lastmod.text = str(date.today())
priority = ET.SubElement(url_element, "priority")
priority.text = "0.8"
tree = ET.ElementTree(root)
ET.indent(tree, space=" ")
tree.write("sitemap.xml", xml_declaration=True, encoding="UTF-8")
print("sitemap.xml created successfully")
Run this script, and it outputs a properly formatted sitemap.xml you can deploy immediately. For dynamic sites, you'd pull URLs from a database or CMS API rather than a static list.
Method 5: Generate a Sitemap with Node.js
For JavaScript developers, the sitemap npm package makes this straightforward:
npm install sitemap
const { SitemapStream, streamToPromise } = require('sitemap');
const { Readable } = require('stream');
const fs = require('fs');
const links = [
{ url: '/', changefreq: 'weekly', priority: 1.0 },
{ url: '/about/', changefreq: 'monthly', priority: 0.8 },
{ url: '/blog/', changefreq: 'daily', priority: 0.9 },
{ url: '/contact/', changefreq: 'yearly', priority: 0.5 },
];
const stream = new SitemapStream({ hostname: 'https://www.example.com' });
streamToPromise(Readable.from(links).pipe(stream)).then((data) => {
fs.writeFileSync('./sitemap.xml', data.toString());
console.log('Sitemap generated successfully');
});
Working With Sitemap Index Files
If your site has more than 50,000 URLs (the maximum per sitemap file), you need a sitemap index file — a parent file that references multiple individual sitemaps:
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.example.com/sitemap-pages.xml</loc>
<lastmod>2024-11-10</lastmod>
</sitemap>
<sitemap>
<loc>https://www.example.com/sitemap-blog.xml</loc>
<lastmod>2024-11-10</lastmod>
</sitemap>
<sitemap>
<loc>https://www.example.com/sitemap-products.xml</loc>
<lastmod>2024-11-10</lastmod>
</sitemap>
</sitemapindex>
Even for smaller sites, using a sitemap index can be a clean organizational strategy — separating blog posts, products, and static pages into their own files makes management easier and gives you more granular data in Google Search Console.
What to Include (and Exclude) in Your XML Sitemap
This is where many site owners go wrong. Your sitemap should only contain URLs that you want indexed and that return a 200 HTTP status code.
Include:
- Canonical pages (the preferred version of any URL)
- Key landing pages, service pages, product pages
- Blog posts and articles you want indexed
- Category and tag pages (if they have unique, valuable content)
Exclude:
- Pages with
noindexmeta tags (a sitemap URL with noindex is contradictory and confuses crawlers) - Paginated pages beyond page 1 (e.g.,
/blog/page/2/,/blog/page/3/) - Duplicate content pages (use canonical tags to handle these instead)
- Admin pages, login pages, thank-you pages
- URLs that redirect (301 or 302) — only include the final destination URL
- URLs returning 404 or 5xx errors
A clean, accurate sitemap is far more valuable than a bloated one. Including irrelevant or low-quality URLs can actually dilute crawl efficiency.
Adding Your Sitemap to robots.txt
Once your sitemap is live, add a reference to it in your robots.txt file. This helps search engines discover it without you having to submit it manually every time:
User-agent: *
Disallow: /admin/
Disallow: /login/
Sitemap: https://www.yoursite.com/sitemap.xml
Place this at the bottom of your robots.txt file. Both Google and Bing automatically check robots.txt for sitemap references during crawling.
How to Submit Your XML Sitemap to Google Search Console
Creating the sitemap is only half the job. You need to tell Google about it.
Step 1: Log in to Google Search Console
Step 2: Select your property (make sure your site is verified first)
Step 3: In the left sidebar, click Sitemaps under the Index section
Step 4: In the "Add a new sitemap" field, enter your sitemap URL (just the path, e.g., sitemap.xml)
Step 5: Click Submit
Google will then crawl your sitemap and show you:
- How many URLs were submitted
- How many were indexed
- Any errors or warnings
Check back after 24–48 hours to review the results. If you see a gap between submitted and indexed URLs, investigate those pages — they may have thin content, noindex tags, or canonicalization issues.
Submitting to Bing Webmaster Tools
Don't forget Bing. Log into Bing Webmaster Tools, navigate to Sitemaps, and submit your sitemap URL there as well. Bing also powers Yahoo search, so this extends your reach further.
Common XML Sitemap Mistakes to Avoid
Even experienced developers make these errors:
Including non-canonical URLs: If you have
https://example.comandhttps://www.example.comboth in your sitemap, you're sending mixed signals. Pick one and stick with it.Outdated
<lastmod>dates: If you setlastmodto a date years ago and never update it, Googlebot may deprioritize recrawling that page. Keep it accurate.Sitemap not accessible: Run a quick check — open your sitemap URL in a browser. If you get a 404, something is wrong with your file placement or server configuration.
Exceeding the 50,000 URL limit: Split into multiple sitemaps and use a sitemap index file.
Including blocked URLs: If a URL is blocked in
robots.txt, don't include it in your sitemap. It creates a conflict that wastes crawl resources.Using relative URLs: Every
<loc>entry must be an absolute URL including the protocol (https://).
Keeping Your Sitemap Updated
An XML sitemap isn't a set-it-and-forget-it file. It needs to stay current.
- For CMS users: Plugins like Yoast and Rank Math update your sitemap automatically on publish. Confirm this is working by checking the sitemap after publishing a new post.
- For static sites: Set a reminder to update your sitemap whenever you add or remove pages. Or automate it using a CI/CD pipeline that regenerates the sitemap on each deployment.
- For large e-commerce sites: Consider a dynamic sitemap generated server-side from your product database, ensuring it always reflects your current inventory.
You can also use the Sitemap Generator on OpDeck periodically to regenerate and compare against your current live sitemap, catching any pages that may have been accidentally excluded or added without proper review.
Conclusion
Learning how to create an XML sitemap for SEO is one of the most practical investments you can make in your site's search visibility. It's not complicated, but it does require attention to detail — the right URLs, clean formatting, proper submission, and ongoing maintenance. Whether you go the plugin route in WordPress, write one manually, or use a script to automate the process, the core principles are the same: include only indexable, canonical URLs, keep the file accurate, and make sure search engines can find it.
Ready to get started? Use OpDeck's Sitemap Generator to create a properly formatted XML sitemap for your site in minutes — no coding required. Once it's live, submit it to Google Search Console and Bing Webmaster Tools, and you'll have a solid foundation for better crawl coverage and faster indexing.