Skip to content
Розсилки Mail Cabinet Choose a plan

How to set up robots.txt and sitemap.xml in WordPress: bench-tested

How to set up robots.txt and sitemap.xml in WordPress: bench-tested

For a typical WordPress site, robots.txt should be short: Disallow: /wp-admin/, Allow: /wp-admin/admin-ajax.php, optional rules for internal search and the cart, and a Sitemap line with the full sitemap URL. Do not block /wp-content/ or /wp-includes/, and use noindex, not Disallow, to remove a page from Google. WordPress already ships a sitemap at /wp-sitemap.xml: make sure it lists only the content types you want and no redirecting URLs.

How we tested

  • RichHost test bench, an isolated 2 vCPU / 8 GB container: Ubuntu 24.04, nginx 1.24, PHP 8.3-FPM, MariaDB 10.11, WordPress 6.7.2 with the Twenty Twenty-Five theme, 301 posts, 1 page, 1 category, 1 author, no SEO plugins. October 2026.
  • Server responses were captured with curl, settings were changed with WP-CLI. Core behaviour was checked against the wp-includes source of 6.7.2; line numbers are given below.
  • robots.txt rules were tested with two parsers: Google’s open-source robotstxt library (C++, built from GitHub, commit of 2026-04-01) and Python 3.11 urllib.robotparser. Reference: Google’s documentation and RFC 9309, checked on 2026-10-25.
  • After the tests the bench was restored: blog_public = 1, test mu-plugins and the robots.txt file removed.

What WordPress serves by default

If there is no robots.txt file in the site root, WordPress generates one with do_robots() (wp-includes/functions.php, lines 1701-1727). This is what our bench returned:

$ curl -si http://127.0.0.1:8080/robots.txt
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Link: <http://127.0.0.1:8080/wp-json/>; rel="https://api.w.org/"

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

Sitemap: http://127.0.0.1:8080/wp-sitemap.xml

The first three lines come from do_robots(); the Sitemap line is appended by the robots_txt filter in WP_Sitemaps (class-wp-sitemaps.php, lines 259-264), and only while the site is open to search engines. The Link: wp-json header gives away that PHP, not the web server, produced the response.

What “Discourage search engines from indexing this site” changes

This checkbox under Settings > Reading stores blog_public = 0. We switched it on:

$ wp --allow-root --path=/var/www/bench option update blog_public 0
Success: Updated 'blog_public' option.
$ curl -s http://127.0.0.1:8080/robots.txt
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
$ curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:8080/wp-sitemap.xml
404
$ curl -s http://127.0.0.1:8080/ | grep -o "<meta name='robots'[^>]*>"
<meta name='robots' content='noindex, nofollow' />

So robots.txt barely changes: only the Sitemap line disappears, and no Disallow: / is added (core has worked this way since 5.3). Instead, every sitemap returns 404 (class-wp-sitemaps.php, lines 89 and 176-178) and every page gets a noindex, nofollow meta tag (robots-template.php, line 71). If a freshly launched site does not show up in Google, check the meta tag: robots.txt looks perfectly normal.

A physical robots.txt file overrides the virtual one

When we put a robots.txt file in the site root, the response changed:

$ curl -si http://127.0.0.1:8080/robots.txt
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 146
Last-Modified: Sun, 25 Oct 2026 14:06:54 GMT
ETag: "6ade0cfe-92"

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=
Disallow: /search/

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

Content-Length, ETag and Last-Modified appeared and the wp-json header is gone: nginx served the file and WordPress never ran. The reason is try_files $uri $uri/ /index.php?$args: a real file is tried first, and only if it is missing does the request go to index.php. In Apache the same is done by RewriteCond %{REQUEST_FILENAME} !-f. Takeaway: once the file exists, robots.txt editors in plugins and the robots_txt filter no longer change anything. The reverse also happens: when rewrite rules are broken, the virtual robots.txt and /wp-sitemap.xml return 404 along with every post, and the cause is the same as with a WordPress 404 on all pages.

The built-in /wp-sitemap.xml: what is actually in it

The sitemap index on the bench listed four files:

$ curl -s http://127.0.0.1:8080/wp-sitemap.xml | grep -o '<loc>[^<]*'
<loc>http://127.0.0.1:8080/wp-sitemap-posts-post-1.xml
<loc>http://127.0.0.1:8080/wp-sitemap-posts-page-1.xml
<loc>http://127.0.0.1:8080/wp-sitemap-taxonomies-category-1.xml
<loc>http://127.0.0.1:8080/wp-sitemap-users-1.xml
Sitemap file Status URLs Why (WordPress 6.7.2)
wp-sitemap-posts-post-1.xml 200 301 Only posts with status publish (class-wp-sitemaps-posts.php, line 244), with lastmod
wp-sitemap-posts-page-1.xml 200 2 1 page + the home page, added because the front page shows latest posts (line 109)
wp-sitemap-taxonomies-category-1.xml 200 1 Only non-empty terms, hide_empty (class-wp-sitemaps-taxonomies.php, line 204)
wp-sitemap-users-1.xml 200 1 Authors with published posts (class-wp-sitemaps-users.php, line 157)
wp-sitemap-taxonomies-post_tag-1.xml 404 0 No tags on the bench, so the file is not in the index either
wp-sitemap-posts-attachment-1.xml 404 0 Attachments are always excluded (class-wp-sitemaps-posts.php, line 38)

The limit is 2,000 URLs per file: wp_sitemaps_get_max_urls() returns apply_filters( 'wp_sitemaps_max_urls', 2000, $object_type ) (wp-includes/sitemaps.php, lines 81-90), and the index holds up to 50,000 files (class-wp-sitemaps-index.php, line 35). Google accepts up to 50,000 URLs per file, so 2,000 is WordPress’s own choice. To see pagination with 301 posts, we temporarily lowered the limit to 100:

add_filter( 'wp_sitemaps_max_urls', function ( $max, $object_type ) { return 100; }, 10, 2 );

wp-sitemap-posts-post-1.xml: 200 loc=100
wp-sitemap-posts-post-2.xml: 200 loc=100
wp-sitemap-posts-post-3.xml: 200 loc=100
wp-sitemap-posts-post-4.xml: 200 loc=1
wp-sitemap-posts-post-5.xml: 404 loc=0

New files are added to the index automatically, so /wp-sitemap.xml is the only URL you need in Search Console and robots.txt. Yoast SEO and Rank Math disable this sitemap and serve their own /sitemap_index.xml: point to that one instead, and never run two generators at once.

How to remove authors, tags and extra post types from the sitemap

Core has three filters for this. We tested them in an mu-plugin: a file in wp-content/mu-plugins/sitemap-cleanup.php loads automatically and cannot be switched off by accident with other plugins.

<?php
/**
 * Plugin Name: Sitemap cleanup (no authors, no tags, no formats)
 */
// 1. Remove the users (authors) sitemap entirely.
add_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) {
	return ( 'users' === $name ) ? false : $provider;
}, 10, 2 );

// 2. Remove taxonomies you do not want in search (here: tags).
add_filter( 'wp_sitemaps_taxonomies', function ( $taxonomies ) {
	unset( $taxonomies['post_tag'], $taxonomies['post_format'] );
	return $taxonomies;
} );

// 3. Remove a post type (on the bench: pages, to prove the filter works).
add_filter( 'wp_sitemaps_post_types', function ( $post_types ) {
	unset( $post_types['page'] );
	return $post_types;
} );
$ curl -s http://127.0.0.1:8080/wp-sitemap.xml | grep -o '<loc>[^<]*'
<loc>http://127.0.0.1:8080/wp-sitemap-posts-post-1.xml
<loc>http://127.0.0.1:8080/wp-sitemap-taxonomies-category-1.xml
wp-sitemap-posts-page-1.xml: 404
wp-sitemap-users-1.xml: 200   (home page HTML, not XML)

The filters worked: only posts and categories are left in the index. You do not need the third block on a live site; it only proves the filter works, and in practice you use it for something like a plugin’s public post type. A non-obvious detail: once the users provider is removed, the old wp-sitemap-users-1.xml URL returns 200 with an HTML page instead of 404, because render_sitemaps() simply returns when there is no provider (class-wp-sitemaps.php, lines 198-202). If you ever submitted that file separately in Search Console, remove it there and submit only the index.

How Google reads the rules: a test with two parsers

Google applies only one group, the one with the most specific User-agent, and inside it the rule with the longest path wins. If Allow and Disallow are the same length, Google picks the least restrictive one, Allow (RFC 9309, section 2.2.2). * matches any sequence of characters, $ marks the end of the URL (section 2.2.3), and paths are case-sensitive. Python’s urllib.robotparser, which many scripts and online checkers rely on, behaves differently:

$ ./robots A_wp_default.txt Googlebot https://example.com/wp-admin/admin-ajax.php
user-agent 'Googlebot' with URI 'https://example.com/wp-admin/admin-ajax.php': ALLOWED
$ python3 -c "...rp.can_fetch('Googlebot', 'https://example.com/wp-admin/admin-ajax.php')"
False

For the default WordPress robots.txt, Python says “blocked” because it takes the first matching rule in file order, and Disallow: /wp-admin/ comes first. In total we tested 18 URLs against 8 rule sets, and the results differed for 7:

Rules URL Google robotparser
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
/wp-admin/admin-ajax.php allowed blocked
same /wp-admin/options.php blocked blocked
Disallow: /*?s= /?s=hosting blocked allowed
Disallow: /*?s= /blog/?s=hosting blocked allowed
Disallow: /*.pdf$ /files/price.pdf blocked allowed
Disallow: /*.pdf$ /files/price.pdf?v=2 allowed allowed
Disallow: /*add-to-cart= /shop/?add-to-cart=15 blocked allowed
Disallow: /shop
Allow: /shop/
/shop/item-1 allowed blocked
same /shopping-guide blocked blocked
Disallow: /folder
Allow: /folder
/folder/page allowed blocked
Disallow: /Private/ /private/a allowed allowed
Disallow: /кошик/ (Cyrillic) /%D0%BA%D0%BE%D1%88%D0%B8%D0%BA/1 blocked blocked
Comparison of Google robotstxt and Python robotparser decisions for six robots.txt rules
Yes means crawling allowed, no means blocked. Results differed for 7 of 18 URLs

Both parsers agreed on case sensitivity, non-Latin paths (a rule with /кошик/ matches the percent-encoded URL), an empty Disallow: and a separate Googlebot group. Two practical lessons. First, Disallow: /shop is a prefix, so it also blocks /shopping-guide. Second, test rules with the robots.txt report and URL Inspection in Search Console or with Google’s library, not with a tool built on Python robotparser. By the way, robotparser reads Crawl-delay (it returned 10), while Google ignores that directive.

Common mistakes and what actually happens

Mistake What happens Do this instead
Disallow: /wp-content/ and /wp-includes/ On the bench all 6 external CSS and JS files of a post became off-limits to Googlebot (checked with Google’s parser), and so did images in /uploads/. Google warns it then analyses such pages worse Never block these folders
Disallow to remove a page from search Google does not crawl the page and never sees noindex; the URL can stay in results without a description if other pages link to it Leave the page crawlable and add noindex, or delete it (404/410)
Redirecting, 404 or noindex URLs in the sitemap Google asks for only the URLs you want in search; these add errors and exclusions to reports After URL changes, update the sitemap and set up a 301 redirect from the old URLs
Crawl-delay for Googlebot Ignored by Google Find the cause of the load in server logs
robots.txt returns 500 or 503 For the first 12 hours Google stops crawling the site, then for up to 30 days it uses the last cached copy; after that, if the site is generally available, it acts as if there were no file Fix the cause of the 503 Service Unavailable error right away
robots.txt returns 404 or 403 Google treats all 4xx codes except 429 as “no restrictions” If you need rules, the file must return 200
A separate Googlebot group without the general rules Rules from the * group stop applying to Googlebot Repeat every needed Disallow in that group

These mistakes show up most often during a move or a domain change: the new host ends up with a staging robots.txt containing Disallow: /, or with a sitemap of old URLs. That is why robots.txt and the sitemap belong in every hosting migration checklist.

Recommended robots.txt for a typical WordPress site

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /*?s=
Disallow: /search/
# only for WooCommerce:
Disallow: /*add-to-cart=

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

We tested this file with Google’s library on 17 typical URLs (output shortened, URLs with the same result grouped):

/  /post-1/  /category/news/  /page/2/  /feed/        ALLOWED
/wp-sitemap.xml  /wp-login.php                      ALLOWED
/wp-admin/admin-ajax.php                            ALLOWED
/wp-content/themes/twentytwentyfive/style.css?ver=1.0  ALLOWED
/wp-content/uploads/2026/10/photo.webp              ALLOWED
/wp-includes/js/comment-reply.min.js?ver=6.7.2      ALLOWED
/wp-admin/                                          BLOCKED
/?s=hosting  /category/news/?s=x  /search/hosting/  BLOCKED
/shop/?add-to-cart=15                               BLOCKED
/product/x/?add-to-cart=15&quantity=2              BLOCKED

Replace example.com with your domain; with Yoast or Rank Math use sitemap_index.xml. The search lines are optional: WordPress 6.7.2 already marks search pages noindex, follow (default-filters.php, line 272). Add Disallow: /*?s= when logs or Search Console show lots of crawled search URLs, for example spam queries. If such URLs are already indexed, first let Google see the noindex and only then block them.

What to do in your case

If Do this
The site is still in development A web-server password plus the “Discourage search engines” checkbox; Disallow: / does not keep URLs out of the index
You need a page out of Google noindex with crawling allowed; once it drops out, you may block it
A page was deleted or moved 404/410 or a 301 to the replacement, new URL in the sitemap
Single author, author archive duplicates the blog Remove users from the sitemap with wp_sitemaps_add_provider
Google crawls thousands of search or filter URLs Disallow with * for the parameters, checked with Google’s library
An SEO plugin with its own sitemap is active One sitemap; its URL in robots.txt and Search Console
Googlebot overloads the server Not Crawl-delay: find the cause in the access logs

Checklist before launch and after changes

  • curl -si https://your-domain/robots.txt returns 200 and text/plain, not 404, 5xx or HTML.
  • No Disallow: / and no rules for /wp-content/ or /wp-includes/.
  • Allow: /wp-admin/admin-ajax.php is there, and a Sitemap line with the full https URL of the right host.
  • “Discourage search engines” is off: no noindex, nofollow on the home page and /wp-sitemap.xml does not return 404.
  • Only one sitemap is active: the built-in one or the SEO plugin’s.
  • No redirecting, 404 or noindex URLs in the sitemap; spot-check 10-20 URLs with curl -sI.
  • Unneeded sections (authors, tags, utility post types) removed with filters.
  • Sitemap submitted in Search Console, robots.txt report without errors.
  • Each subdomain and protocol has its own robots.txt: a file applies only to its own host.
Four numbers from the robots.txt and WordPress sitemap test on the bench
Key results of the robots.txt and /wp-sitemap.xml test

FAQ

How long until Google sees a new robots.txt?

Google usually caches the file for up to 24 hours. You can speed it up by requesting a recrawl in the robots.txt report in Search Console.

Why does an online validator say “blocked” while Search Console says “allowed”?

Many validators use Python robotparser or similar logic: first rule in file order and no support for * and $. Google picks the longest rule, so trust Search Console or Google’s library.

Is there a size limit for robots.txt?

Yes, Google reads the first 500 KiB and ignores the rest. A WordPress site will never get close unless a buggy plugin generates the file.

Can I block AI crawlers without losing Google?

Yes, they have their own tokens, for example GPTBot, ClaudeBot and Google-Extended. A group with them and Disallow: / does not affect Googlebot, but it is only a request: badly behaved bots ignore robots.txt.

A stable server that never returns 5xx for robots.txt and the sitemap is part of SEO too. If you are choosing a home for WordPress, read our WordPress hosting requirements and compare RichHost shared hosting plans with NVMe disks and free Let’s Encrypt SSL.

Sources (checked on 2026-10-25): How Google interprets the robots.txt specification (updated 2026-10-23); Introduction to robots.txt and Block indexing with noindex (updated 2025-12-10); Build and submit a sitemap (updated 2026-07-08); RFC 9309 Robots Exclusion Protocol (September 2022); google/robotstxt; WordPress 6.7.2 source, wp-includes/sitemaps.

More on this topic

All articles
FileZilla: How to Connect to Hosting via FTP and SFTP, Common Errors
Hosting Guides and Tutorials25.10.2026

FileZilla: How to Connect to Hosting via FTP and SFTP, Common Errors

How to connect FileZilla to hosting over SFTP or FTP with TLS: where to find the host, login and port, Site Manager…

IMAP and SMTP Settings: Ports 993, 465, 587 and Mail Servers
Domains and DNS15.10.2026

IMAP and SMTP Settings: Ports 993, 465, 587 and Mail Servers

Which servers and ports to use for IMAP, POP3 and SMTP (993, 995, 465, 587), how to set up email in Gmail,…

How to Connect via SSH from Windows, macOS and Linux: Step by Step
Hosting Guides and Tutorials27.09.2026

How to Connect via SSH from Windows, macOS and Linux: Step by Step

A step-by-step guide on how to connect via SSH from Windows, macOS and Linux with the terminal or PuTTY, set up key…