Website & SEO Guides

How to Add a Sitemap to robots.txt (With Examples)

ShareXFacebookLinkedIn
A rules file card linked by a glowing route line to a branching tree of page nodes

To add a sitemap to robots.txt, put one line in the file: Sitemap: followed by the full, absolute URL of your sitemap, such as Sitemap: https://example.com/sitemap.xml. The line can go anywhere in the file, it does not belong to any particular User-agent group, and you can add it more than once if you have several sitemaps.

This guide shows the exact syntax, how to find your sitemap address in WordPress, and the mistakes that stop the line from working.

Why Add a Sitemap to robots.txt?

A sitemap lists the URLs you want search engines to know about. Crawlers check robots.txt before they crawl a site, so a Sitemap line there gives every compliant crawler a direct pointer to your sitemap without you having to submit it to each search engine. Google, Bing, and other major search engines support the field.

It is a convenience, not a requirement. If you already submit your sitemap in Google Search Console, the robots.txt line is a useful extra that helps other crawlers find it too.

The Syntax

According to Google’s robots.txt specification, the sitemap field takes the complete URL of a sitemap or sitemap index file. The address must be fully qualified, including the protocol and host, such as https://:

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

Some points about the line:

  • It must be an absolute URL. Sitemap: /sitemap.xml is not valid.
  • It is not tied to a user agent. Crawlers can follow it regardless of where it sits in the file.
  • You can list several. Add one Sitemap: line for each file.
  • It can point to another host. The sitemap does not have to live on the same host as the robots.txt file.
  • The value is case sensitive, so copy the address exactly.

Examples

One sitemap

User-agent: *
Disallow:

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

A sitemap index

If your sitemap is split into several files, point to the index file that lists them:

Sitemap: https://example.com/sitemap_index.xml

Several sitemaps

Sitemap: https://example.com/post-sitemap.xml
Sitemap: https://example.com/page-sitemap.xml

A WordPress example

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: https://example.com/wp-sitemap.xml

How to Find Your Sitemap URL in WordPress

The address depends on what generates your sitemap:

SourceTypical address
WordPress built-in sitemap/wp-sitemap.xml
Yoast SEO/sitemap_index.xml
Rank Math/sitemap_index.xml

Open the address in your browser to confirm it loads and shows a list of URLs or other sitemaps. If you use an SEO plugin, check its settings for the exact address, because plugins can replace the built-in sitemap.

How to Add the Line

  1. Open your robots.txt. In WordPress, you may edit it through an SEO plugin, or through a physical file in your site root. If both exist, the physical file takes precedence.
  2. Add the Sitemap: line with your full sitemap URL, preferably on its own line below your rules.
  3. Save the file.
  4. Open yourdomain.com/robots.txt and confirm the line appears.
  5. Open the sitemap address itself and confirm it loads without errors.

If you would rather not edit by hand, the Robots.txt Generator lets you build a file and download it. For the full process, see how to create a robots.txt file.

Also Submit Your Sitemap in Search Console

The robots.txt line helps crawlers discover your sitemap, but submitting it in Google Search Console lets you see whether Google could read it and how many URLs it found. Do both. You do not need to submit the robots.txt file itself.

What Belongs in the Sitemap

A sitemap is most useful when it lists only pages you want in search results. Include canonical, indexable URLs, and leave out pages you have blocked or marked noindex. A sitemap that points to noindexed or redirected URLs sends mixed signals. See robots.txt vs. noindex for the difference between blocking and noindexing.

Common Mistakes

  • Using a relative URL. The value must start with https:// and include the host.
  • Wrong protocol or host. If your site is on https and the www version, the sitemap address should match.
  • Blocking the sitemap itself. Crawlers can follow the sitemap line only if the sitemap URL is not disallowed.
  • Pointing to a sitemap that does not exist or returns an error. Always open the address yourself.
  • Typos and case differences. The value is case sensitive.
  • Forgetting that the line disappears with some settings. In WordPress, ticking “Discourage search engines” can remove the built-in sitemap and its robots.txt line.
  • Listing a sitemap for a different subdomain in the wrong file. Each host’s robots.txt should list the sitemaps for that host.

Conclusion

Adding a sitemap to robots.txt takes one line: Sitemap: and the full URL. Check that the address loads, keep the sitemap limited to pages you want indexed, and submit it in Search Console as well. It is one of the cheapest technical SEO improvements you can make.

Frequently Asked Questions (FAQ)

How do I add a sitemap to robots.txt?

Add a line that reads Sitemap: https://yourdomain.com/sitemap.xml, using the full URL of your own sitemap, anywhere in the file.

Does the sitemap line have to be an absolute URL?

Yes. It must include the protocol and host, for example https://example.com/sitemap.xml.

Can I list more than one sitemap in robots.txt?

Yes. Add a separate Sitemap: line for each sitemap or sitemap index.

Where is my WordPress sitemap?

The built-in WordPress sitemap is usually at /wp-sitemap.xml. Yoast SEO and Rank Math typically use /sitemap_index.xml. Open the address to confirm.

Do I still need to submit my sitemap to Google Search Console?

It is a good idea. The robots.txt line helps crawlers find the sitemap, while Search Console shows whether Google could read it and how many URLs it found.

Scroll to Top