A sitemap tells search engines which URLs on your site you want them to find. Here’s how to build one that does that job well.
Step 1: Decide what belongs in it
List the canonical URLs you want to appear in search. Leave out redirects, error pages, noindex pages and duplicates. A sitemap doesn’t need to list every URL your site can produce, only the ones you want indexed.
Step 2: Choose a format
XML is the standard for search engines. It’s simple to read and supports images, video and news. RSS feeds and plain text URL lists also work. An HTML sitemap is a separate thing, a page that helps visitors find their way around.
Step 3: Generate it
Let your software do this if you can, because a generated sitemap stays correct as your site changes. On WordPress, use our free plugin or the basic sitemap built into WordPress. Most other platforms have an option or extension. A file can hold up to 50,000 URLs or 50 MB uncompressed, and larger sites split theirs and use a sitemap index.
Step 4: Tell search engines
Submit the sitemap’s URL once in Google Search Console and Bing Webmaster Tools, which also covers Yahoo, since Yahoo’s results are powered by Bing. Add a Sitemap: line to your robots.txt so other crawlers can find it too.
Step 5: Keep it accurate
Remove deleted pages and add new ones, and update lastmod only when a page changes significantly. Check the Sitemaps report in Search Console now and then for errors.
For the official details, see Google’s guide to building and submitting a sitemap.