WordPress robots.txt: the default file, safe templates and what not to block
What WordPress puts in robots.txt by default, how to edit it with Yoast, Rank Math, AIOSEO or a file, templates for blogs and WooCommerce, AI crawler rules, and how to test the result.
By Reagan Baker, Sr. Software Development Engineer · Published · Updated
Short version
- Most WordPress sites need no custom robots.txt. The default blocks
/wp-admin/, allowsadmin-ajax.phpand lists the sitemap. - robots.txt controls crawling, not indexing. To keep a page out of Google, use
noindexand leave the page crawlable. - Never block CSS, JavaScript or
/wp-content/uploads/. - Edit the file in one place only, either an SEO plugin or a file on the server.
- Test the live file after every change.
What robots.txt does and doesn't do
robots.txt is a plain text file at the root of a host, such as https://yourdomain.com/robots.txt. Crawlers that follow the Robots Exclusion Protocol (RFC 9309), including Googlebot and Bingbot, read it before they fetch pages. It has four main directives: User-agent, Disallow, Allow and Sitemap.
What it doesn't do:
- It doesn't remove pages from Google. A blocked URL can still be indexed when other pages link to it, and it then shows in results with no description. To keep a page out of results, let Google crawl it and add
<meta name="robots" content="noindex">or anX-Robots-Tag: noindexheader. - It doesn't work together with noindex. If you block a page that already carries
noindex, Google can't fetch the page, so it never sees the tag. Leave the page crawlable until it has dropped out of the index. - It isn't security. Anyone can read the file, and bad bots ignore it. Protect private areas with a login.
WordPress's default robots.txt
If no robots.txt file exists on the server, WordPress builds one when /robots.txt is requested. You won't find it over FTP, because PHP generates it on each request. On WordPress 5.5 and later, a site that search engines may index gets:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://yourdomain.com/wp-sitemap.xmlUser-agent: *applies the rules to every crawler.Disallow: /wp-admin/keeps crawlers out of the dashboard.Allow: /wp-admin/admin-ajax.phpis an exception to that rule, because themes and plugins load front-end content through this file.- The
Sitemap:line points to the sitemap that WordPress core has built in since 5.5. Core adds it only while the site is open to search engines. Yoast, Rank Math and AIOSEO switch off the core sitemap and list their own.
"Discourage search engines from indexing this site" (Settings → Reading) no longer adds Disallow: /. Since WordPress 5.3, the box puts a noindex robots meta tag on every page and removes the Sitemap: line, and it leaves the rest of robots.txt unchanged. This matters at launch: if a staging site goes live with the box still ticked, every page carries noindex, even though robots.txt looks normal.
A physical robots.txt in the site root replaces the generated one completely.
How to edit it
Choose one method. A plugin editor can't change a physical file that it doesn't manage, so edits in two places end with one of them ignored.
Yoast SEO
- Go to Yoast SEO → Tools → File editor.
- Click Create robots.txt file if the site has none.
- Edit the rules and click Save changes to robots.txt.
Yoast writes a physical file, so the server must allow WordPress to write files. The File editor is missing when DISALLOW_FILE_EDIT is set in wp-config.php.
Rank Math
- Switch to Advanced Mode if you are in Easy Mode.
- Go to Rank Math SEO → General Settings → Edit robots.txt.
- Edit the rules and click Save Changes.
Rank Math edits the virtual file. If a physical robots.txt exists, it shows a warning and doesn't let you edit, because the physical file takes priority.
All in One SEO
- Go to All in One SEO → Tools → Robots.txt Editor.
- Turn on Enable Custom Robots.txt.
- Add rules with the User Agent, Rule and Directory Path fields, or import an existing file.
- Click Save Changes.
A file on the server
- Connect over SFTP, or open the host's file manager.
- Go to the WordPress root, the folder that holds
wp-config.php(oftenpublic_html). - Create
robots.txt, all lower case and saved as plain UTF-8. - Paste the rules and save.
Templates
Keep the file short. Extra rules rarely help rankings, and each one is a chance to block something you need.
Blog or business site
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=
Disallow: /search/
Sitemap: https://yourdomain.com/sitemap_index.xml/?s=and/search/are internal search results. They waste crawling, and spammers fill them with junk queries.- Use your real sitemap URL:
/wp-sitemap.xmlfor WordPress core,/sitemap_index.xmlfor Yoast and Rank Math,/sitemap.xmlfor AIOSEO. - Blocking
/wp-login.phpis optional. Google doesn't index login pages, so the rule changes little.
WooCommerce
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /cart/
Disallow: /checkout/
Disallow: /my-account/
Disallow: /*add-to-cart=
Disallow: /*orderby=
Disallow: /*filter_
Disallow: /?s=
Disallow: /search/
Sitemap: https://yourdomain.com/sitemap_index.xml- Match your slugs. WooCommerce lets you rename the cart, checkout and account pages, and translated stores often use other words. Use the paths your store really has.
- Check the filter rule before you use it. Leave out
/*filter_if you want some filtered category pages to rank, and usenoindexor canonical tags on the filtered pages you don't want. *matches any run of characters, so no*is needed at the end of a rule.Disallow: /*orderby=already covers?orderby=price&....
What not to block
- CSS and JavaScript. Don't block
/wp-content/themes/,/wp-content/plugins/or/wp-includes/, and don't add rules such as/*.js$. Google renders pages much as Chrome does, and a page it can't render properly can be judged as broken or not mobile friendly. /wp-content/uploads/. Your images and PDFs live there. Blocking it takes your images out of Google Images./wp-content/as a whole. That one line blocks all of the above.- Pages you want removed or consolidated. Google has to fetch a page to read its
noindexorrel="canonical".
AI crawlers (optional)
These tokens opt out of AI training without affecting Google or Bing search:
GPTBot: OpenAI's training crawler.ClaudeBot: Anthropic's crawler.Google-Extended: Google's token for Gemini training and grounding. It is a control, not a separate bot, and blocking it doesn't change crawling or ranking in Google Search.CCBot: Common Crawl, whose archive many AI datasets use.
User-agent: GPTBot
Disallow: /
User-agent: ClaudeBot
Disallow: /
User-agent: Google-Extended
Disallow: /
User-agent: CCBot
Disallow: /A crawler obeys only the most specific group that names it. So these blocks don't affect Googlebot, which still follows the User-agent: * group. The large AI companies honour these rules. Scrapers that ignore robots.txt need a firewall or CDN rule instead.
How to test it
- Open the live file. Load
https://yourdomain.com/robots.txtin a private window. Check that it returns 200 and shows the new rules. If you still see the old file, clear the page cache or CDN cache. - Test the URLs that matter. Paste the file into the RoamSEO robots.txt tester, then check a post, a product page, a CSS file and
/wp-admin/against Googlebot and the other crawlers you care about. - Check Search Console. Settings → robots.txt shows the files Google last fetched for your hosts, when it fetched them, the status code and any parsing errors. After an urgent fix, ask for a recrawl there.
Common mistakes
- Launching with "Discourage search engines" still ticked, or with a staging
Disallow: /copied across. - Putting the file in the wrong place. It must be at the root of the host.
/blog/robots.txtis ignored, and each subdomain needs its own file. - Getting the case wrong. The filename must be
robots.txtin lower case. Paths in rules are case sensitive too, soDisallow: /Cart/doesn't block/cart/. - Editing the plugin's virtual file while a physical file exists. The physical file wins.
- Writing a relative sitemap path.
Sitemap:needs the full URL, and that URL must return 200.
Try this workflow on your own site
Paste the prompt above into an agent connected to RoamSEO. Signing up costs nothing and asks for no card.