Skip to content
SEO & crawlers

WordPress robots.txt Best Practice: What to Put In It

A WordPress robots.txt needs four lines: block /wp-admin/, allow admin-ajax.php and add your sitemap. See which extra rules help and which ones hurt.

Published Updated

TL;DR: a good WordPress robots.txt is four lines long. Block /wp-admin/, allow admin-ajax.php, point crawlers at your sitemap, and stop there. The sprawling 40-line blocklists you’ll find on forums mostly break rendering or do nothing at all. The two mistakes that cost rankings are blocking /wp-content/ or /wp-includes/ (breaks how Google renders your pages) and assuming robots.txt can keep a page out of the index (it can’t; that’s a noindex job). The whole file:

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

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

Replace the domain, and if you use an SEO plugin that takes over sitemaps, point the Sitemap line at that plugin’s index instead. That’s it. If your file is longer than this, the extra lines are probably costing you something.

WordPress already generates one, until you create a real file

WordPress ships a virtual robots.txt. When a request comes in for /robots.txt and no actual file exists at your web root, WordPress handles the request in PHP with the do_robots() function and prints the response. Nothing is written to disk. The default output is the wp-admin block above, plus a Sitemap: line for wp-sitemap.xml that core has emitted since WordPress 5.5.

Plain text robots.txt in a browser: User-agent star, Disallow wp-admin, Allow admin-ajax.php and a Sitemap line
The virtual file from our test site with no robots.txt on disk. The address is the test server’s own.

Two things change that output. The first is Settings → Reading → Discourage search engines from indexing this site. Since WordPress 5.3 that checkbox no longer adds Disallow: /. It leaves the wp-admin rules in place, drops the Sitemap: line, and puts a noindex, nofollow robots meta tag on every page instead. Older versions printed Disallow: /. Either way, if the box stays ticked after launch, search engines are told to stay away from the whole site. The second is the robots_txt filter, which plugins and themes use to add their own sitemap lines and rules to the virtual file.

WordPress Reading Settings: Search engine visibility with the checkbox Discourage search engines from indexing this site
The checkbox in Settings > Reading (WordPress 7.1.4 in WordPress Playground).

Now the part that wastes people’s afternoons. A physical robots.txt file in your web root overrides all of it, without any warning. Your web server finds a real file on disk, serves it, and WordPress never loads. The virtual generator doesn’t run. The robots_txt filter doesn’t fire. Your SEO plugin’s robots.txt editor may still show you a nice interface with the right rules in it, and none of that reaches a crawler.

What we measured

We checked each of these cases on 2026-11-16 in WordPress Playground (WordPress 7.1.4, PHP 8.3, Twenty Twenty-Five, WP_DEBUG off), fetching /robots.txt and the front page with curl after each change:

SetupWhat /robots.txt returnedRobots meta on the front page
Fresh install, no file on diskContent-Type: text/plain; charset=utf-8; the three wp-admin lines, a blank line, Sitemap: …/wp-sitemap.xmlmax-image-preview:large
Discourage search engines checkedThe same three lines, no Sitemap: line, no Disallow: /noindex, nofollow
A robots_txt filter appending a GPTBot groupThe default file, then the GPTBot group after the Sitemap lineunchanged
The same filter, plus a static robots.txt in the web rootOnly the static file, served as text/plain; the GPTBot group was goneunchanged
Static file removed againThe filtered virtual file came backunchanged
Where the rules liveEditable in WordPress adminWins on a live request
Virtual (no file on disk)Yes, via the robots_txt filter or a pluginOnly when no physical file exists
Physical file in web rootOnly if the plugin writes to diskAlways

So before you debug anything: open https://yoursite.com/robots.txt in a browser, then connect over SFTP or your host’s file manager and check whether a real robots.txt sits next to wp-config.php and .htaccess. If it does, that file is your robots.txt. Edit it there or delete it and let WordPress take over, but pick one. Running both is how sites end up with a stale sitemap URL nobody can find.

One more layer worth checking on managed WordPress hosting: a host can serve its own robots.txt on staging or development domains, independent of anything in your WordPress files or plugin settings. For example, WP Engine’s robots.txt support page says a site on a WP Engine subdomain gets a virtual robots.txt with User-agent: * and Disallow: /, and that staging and development environments do not reflect custom changes to the file. If a staging copy shows up in search, or production behaves correctly but a *.staging.yourhost.com URL doesn’t, check your host’s panel for this before assuming WordPress or a plugin is at fault.

Why /wp-admin/ is blocked but admin-ajax.php is allowed

/wp-admin/ holds the dashboard. Those URLs are useless in search results and crawling them burns crawl budget on pages that redirect to a login screen. Blocking the directory is uncontroversial.

admin-ajax.php lives inside that directory but isn’t an admin page. It’s the endpoint plugins and themes use to handle front-end AJAX requests: load-more buttons, filtered product grids, calculators, forms. If a crawler can’t fetch it, it can’t see content those features load, and Google renders your page as a visitor would see it with the feature broken.

Whether Google needs to fetch admin-ajax.php on your specific site depends on whether your front end uses it. On many modern sites it doesn’t matter at all, because the theme uses the REST API at /wp-json/ instead. The Allow line is cheap insurance against a real failure mode, not a ranking factor. Keep it because it costs nothing.

Do not block /wp-content/ or /wp-includes/

Google has warned against this since October 2014, when it said that disallowing JavaScript or CSS files in robots.txt “directly harms how well our algorithms render and index your content and can result in suboptimal rankings.”

/wp-content/ contains your themes, plugins and uploads: the stylesheets, scripts and images that make your pages look like pages. /wp-includes/ contains core JavaScript that plugins depend on. Google renders your pages with a headless browser before judging them. Block those directories and the renderer gets a page with no CSS and no images. What Google evaluates is an unstyled wall of text with a broken layout, which affects how it understands your content.

If you inherited a file with these lines, delete them:

Disallow: /wp-content/
Disallow: /wp-includes/
Disallow: /wp-content/plugins/
Disallow: /wp-content/themes/

You can confirm the damage yourself in Google Search Console’s URL Inspection tool. Run a live test on any page, view the rendered screenshot, and check the page resources list for blocked items. If your CSS shows as blocked, that’s the cause.

The Sitemap directive

One line, absolute URL, and it can sit anywhere in the file. It isn’t tied to a User-agent group.

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

Use the sitemap URL that resolves on your site. WordPress core serves wp-sitemap.xml. Most SEO plugins disable core sitemaps and serve their own index at a different path: Yoast SEO and Rank Math both default to /sitemap_index.xml, while All in One SEO defaults to /sitemap.xml. If you’ve switched plugins at any point, it’s common for a robots.txt line to still point at the old one. Load your URL in a browser before you commit it. A Sitemap line pointing at a 404 is worse than no line, because it looks correct in an audit.

Listing multiple sitemaps is fine, one per line. Submitting sitemaps in Search Console is still worth doing separately; the robots.txt directive is how crawlers that never see your Search Console account find them.

robots.txt is not noindex, and it is not security

Blocking a URL does not remove it from Google. Robots.txt governs crawling. If another site links to a blocked URL, Google can index the URL itself, and you get a result with the bare address and a note that no information is available. And there’s a nastier trap: if a page already has a noindex meta tag and you then block it in robots.txt, Google can’t crawl it, can’t see the noindex, and the page can stay indexed indefinitely. To remove a page, allow crawling and serve a noindex meta robots tag in the page head or an X-Robots-Tag HTTP header, as Google’s own guidance on blocking search indexing with noindex explains. Google stopped supporting noindex directives inside robots.txt on September 1, 2019.

Blocking a path does not protect it. Your robots.txt is public by definition. Listing /private-client-files/ tells every visitor and every scanner exactly where to look, and compliance is voluntary: Google honours it, hostile bots do not. Anything that needs protecting needs authentication, an IP restriction, or server-level rules in .htaccess, which the .htaccess generator can write for you, not a line in a text file that advertises the target.

Should you block search results?

This is the one optional rule most guides recommend, and the case for it is weaker than it looks, because WordPress already handles search pages. Since version 5.7, core adds a noindex, follow robots meta tag to every search results page on a public site. In our test that tag appeared on both /?s=hello and the pretty /search/hello/ form, which WordPress also answers.

That changes the trade-off. Blocking search URLs in robots.txt stops Google crawling them, which also stops it seeing that noindex. A blocked search URL that other sites link to can then be indexed as a bare address, which is the opposite of what you wanted.

Your situationWhat to put in robots.txtWhy
A normal amount of search traffic from crawlersNothingCore already marks search pages noindex, follow, and Google has to crawl them to see it
Crawlers hammering search URLs, enough to load your serverDisallow: /?s= and Disallow: /search/Saves the crawl; accept that Google can no longer see the noindex on those URLs
Spam search URLs already indexedNothing yet. Leave them crawlable until they drop out, then decideThe noindex can only remove them if Google can fetch them
You only add Disallow: /?s=Add Disallow: /search/ too, or neither/?s= does not match the /search/term/ URLs WordPress also serves

The robots.txt generator has a search-results option, on by default, that adds Disallow: /?s= only. It is there for the crawl-load case in the second row. If that isn’t your situation, untick it, and if it is, add the /search/ line by hand.

Skip these:

  • Crawl-delay: Google does not support it, and the crawl rate limiter that used to sit in Search Console was deprecated on January 8, 2024. Google’s advice now is to slow Googlebot through server responses; it says Googlebot slows down on its own when a server keeps returning HTTP 500 errors for a range of URLs. Some other crawlers, including Anthropic’s, do read Crawl-delay.
  • Blocking /feed/ or /trackback/: harmless URLs, and feeds are useful.
  • Long lists of individual bot names: a line stops only a bot that reads robots.txt and sends that exact name. A bot that ignores the file ignores the list too.
  • Blocking /wp-json/: it may be what your theme uses to render content.

If what you want is to keep AI bots out, this file is only part of the answer. Every major AI operator documents its own robots.txt token, and some tokens control training while others control whether you appear in AI search answers. The AI crawler token table lists each one, what blocking it costs, and the operator’s own page. If the thing you want gone is an in-dashboard AI writing assistant rather than a crawler, that’s a settings question, covered in disabling WordPress AI features. And if you’re weighing an llms.txt file alongside this one, read what the evidence says about llms.txt first. The two files should never contradict each other.

After you change it

Load https://yoursite.com/robots.txt directly and confirm the served bytes are what you expect, not what your plugin’s editor shows you. Then open the robots.txt report in Search Console, which is available for domain properties and for URL-prefix properties without a path. It shows the robots.txt files Google found for your site, when it last fetched each one, and any rules it could not parse, and you can request a recrawl after fixing a mistake. Finally, run a live URL inspection on a normal page and check that no CSS or JavaScript resources come back blocked.

Google generally caches robots.txt for up to 24 hours, so a fix won’t take effect instantly, and a mistake won’t either. That delay is the reason to verify carefully rather than test in production and wait.

Sources

William Lopez

William Lopez is the founder of Odie Themes. He builds the free WordPress tools and themes on this site and has been on WordPress.org since December 2019.

WordPress.org About

FAQ

Questions

What should a WordPress robots.txt file contain?

Four lines: a wildcard user-agent line, Disallow for /wp-admin/, Allow for /wp-admin/admin-ajax.php, and a Sitemap line with your full sitemap URL. That is exactly what WordPress generates on its own. Everything beyond it is optional, and most of the long blocklists circulating online cause more problems than they solve.

Does WordPress create a robots.txt file automatically?

Yes, but only a virtual one. When a request hits /robots.txt and no real file exists on disk, WordPress builds the response in PHP and serves it as text/plain. It includes the wp-admin rules and, since version 5.5, a Sitemap line for wp-sitemap.xml. Nothing is written to your server.

Why does my robots.txt not match what WordPress should output?

Almost always because a physical robots.txt file exists in your web root. The web server serves that file directly and WordPress never runs, so the virtual output and the robots_txt filter are both bypassed without any warning. Check for a real file at the root of your site before debugging anything else.

Should I block wp-content or wp-includes in robots.txt?

No. Those directories hold the CSS, JavaScript, and images your pages need to render. Blocking them stops Google from fetching those assets, so it evaluates a broken version of your layout. This was common advice years ago and it is now actively harmful.

Can robots.txt keep a page out of Google?

No. Robots.txt controls crawling, not indexing. A blocked URL can still be indexed if other pages link to it, appearing in results with no description. To keep a page out of the index, allow crawling and serve a noindex meta robots tag or X-Robots-Tag header instead.

Is robots.txt a security measure?

No, the opposite. The file is public at yoursite.com/robots.txt and anyone can read it, so listing a private directory advertises its location. Well-behaved crawlers honour it voluntarily and malicious scanners ignore it entirely. Protect sensitive paths with authentication or server rules.