Robots.txt for WordPress: Default File, How to Edit It, Best Example
Copy a safe WordPress robots.txt, edit it in Yoast or Rank Math, add your sitemap line and avoid the blocking mistakes that drop pages from Google.

On this page
- How robots.txt works
- The syntax, line by line
- A safe robots.txt for WordPress
- WordPress sitemap XML and robots.txt
- Robots.txt WordPress setups: good, risky and broken
- Robots.txt for WooCommerce stores
- Robots.txt blocks crawling, not indexing
- AI crawlers and robots.txt
- How to test your robots.txt
- Robots.txt, noindex or a password: which one to use
- When to get help
- FAQs
- Robots.txt controls which URLs crawlers may visit, not which pages appear in Google; to keep a page out of search results, use noindex and leave it crawlable.
- Most WordPress sites need only a short file that blocks the admin area, allows admin-ajax.php and lists the XML sitemap, without blocking CSS, JavaScript or uploads.
- Check the live file after every launch or migration, test important URLs with URL Inspection, and decide on AI crawlers deliberately rather than by accident.
A WordPress robots.txt is a small plain-text file at yourdomain/robots.txt, generated automatically unless you upload your own, that tells search engine crawlers which URLs they may crawl. A safe version blocks only /wp-admin/ (allowing admin-ajax.php) and lists your XML sitemap, and everything else should stay crawlable.
The default WordPress robots.txt: WordPress creates a virtual robots.txt automatically (there is no file on the server until you upload one or edit it in an SEO plugin). On a normal site it looks like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://yourdomain.com/wp-sitemap.xml
Short answer: A WordPress robots.txt controls crawling, not indexing. A safe file blocks /wp-admin/ (allowing admin-ajax.php) and lists your XML sitemap, and nothing else important. To keep a page out of Google, use a noindex tag on a crawlable page instead. The biggest risk is a leftover "Disallow: /" from a staging site.
If Search Console is already showing "Indexed, though blocked by robots.txt" or "Blocked by robots.txt", see what those robots.txt statuses mean and how to fix them.
Need a file to start from? The free robots.txt generator uses WordPress-safe defaults and warns about risky rules.
How robots.txt works
- It lives at one address: https://example.com/robots.txt. Each host has its own, so a subdomain such as shop.example.com needs its own file, and http and https versions are treated separately (another reason to redirect everything to one version).
- Crawlers read it before crawling. Google generally caches it for up to a day, so changes aren't picked up instantly.
- It is a request, not a lock. Googlebot, Bingbot and other reputable crawlers follow it. Scrapers and malicious bots ignore it.
- It is public. Anyone can read it, so listing a "secret" folder in it advertises that folder.
- No file is fine. If robots.txt returns a 404, crawlers assume they may crawl everything. A server error is worse: Google may pause crawling until the file loads properly again.
The syntax, line by line
| Line | What it does | Example |
|---|---|---|
| User-agent | Names the crawler the following rules apply to; * means all crawlers | User-agent: Googlebot |
| Disallow | A path the crawler should not request | Disallow: /wp-admin/ |
| Allow | An exception inside a disallowed path | Allow: /wp-admin/admin-ajax.php |
| Sitemap | The full URL of your XML sitemap; can appear anywhere in the file | Sitemap: https://example.com/sitemap_index.xml |
| # | A comment, ignored by crawlers | # Added at launch |
A few rules that trip people up:
- Rules match from the start of the path. "Disallow: /blog" blocks /blog/, but also /blog-tips/ and /blogging-guide/. Add the trailing slash if you mean the folder.
- Paths are case-sensitive. /Images/ and /images/ are different.
- Wildcards: Google and Bing support * for "any characters" and $ for "end of URL", so "Disallow: /*.pdf$" blocks URLs ending in .pdf.
- The most specific rule wins. When an Allow and a Disallow both match, Google follows the longer rule; if they are equal, it follows the Allow.
- Google ignores crawl-delay (Bing respects it), and Google stopped supporting noindex lines in robots.txt in 2019.
A safe robots.txt for WordPress
For a typical business site, this is all you need:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/sitemap_index.xml
It keeps crawlers out of the dashboard while allowing admin-ajax.php, which some themes and plugins use to load content on the front end. Use your own sitemap address: sitemap_index.xml with Yoast or Rank Math, or wp-sitemap.xml with no SEO plugin; see XML sitemaps explained.
Resist adding more. Old advice to block /wp-includes/, /wp-content/plugins/ or /wp-content/themes/ now does harm, because Google renders pages like a browser and needs the CSS and JavaScript in those folders to see your layout. Blocking /wp-content/uploads/ hides your images from Google Images.
Virtual file or real file?
If there is no robots.txt file in your site's root folder, WordPress generates one on the fly, and SEO plugins often add their sitemap line to it. If a real robots.txt file exists, it replaces the generated one completely. To edit it, at the time of writing:
- Yoast SEO: Yoast SEO > Tools > File editor, which can create the file if none exists.
- Rank Math: Rank Math SEO > General Settings > Edit robots.txt. This only works when no physical file exists; if your edits don't appear on the live file, an old physical file is usually the reason.
- Hosting file manager or FTP: upload or edit robots.txt in the same folder as wp-config.php.
WordPress sitemap XML and robots.txt
The Sitemap line is the one addition almost every WordPress robots.txt should have, because it tells every crawler, not only Google, where your XML sitemap lives. Where the WordPress sitemap XML file is depends on your setup:
| Setup | XML sitemap address |
|---|---|
| No SEO plugin (WordPress core) | /wp-sitemap.xml |
| Yoast SEO or Rank Math | /sitemap_index.xml |
| Other SEO or sitemap plugins | Check the plugin settings, then open the URL to confirm it loads |
Use only one sitemap generator: when an SEO plugin is active it normally switches off the core sitemap, but a separate sitemap plugin on top can create a second, conflicting set. List the full https address on the live domain, submit the same address in Search Console, and re-check both after a migration or domain change.
Robots.txt WordPress setups: good, risky and broken
Most robots.txt problems I find on WordPress sites fall into one of three patterns. Compare yours with these.
| File contains | Verdict | Why |
|---|---|---|
| Disallow: /wp-admin/, Allow: /wp-admin/admin-ajax.php, Sitemap line | Good | The WordPress default plus your sitemap; nothing useful is blocked |
| Disallow: /wp-content/ or /wp-includes/ | Risky | Blocks CSS, JavaScript and images Google needs to render pages |
| Disallow: /*? on a store | Risky | Can block paginated, filtered or tracked URLs you want crawled |
| Disallow: / for User-agent: * | Broken | Blocks the whole site, usually left over from a staging copy |
| Sitemap line pointing to an old domain or http | Broken | Sends crawlers to a sitemap that redirects or no longer exists |
A common broken file after a launch looks like this:
User-agent: *
Disallow: /
Sitemap: http://staging.example.in/sitemap_index.xml
And the fixed version:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.in/sitemap_index.xml
Also check Settings > Reading in WordPress: if "Discourage search engines from indexing this site" is ticked, WordPress adds noindex to every page, which is a separate problem from robots.txt and just as damaging.
Robots.txt for WooCommerce stores
Stores create endless URL variations: add-to-cart links, sorting options and every combination of filters. They are all crawlable by default, and on a new store with limited crawling attention they can soak up visits Google could spend on products. A common addition:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /*?add-to-cart=
Disallow: /*?*orderby=
Disallow: /*?*filter_
Sitemap: https://example.com/sitemap_index.xml
Two cautions. First, adjust the filter rule to the parameters your filter plugin actually uses, and never block filtered pages you have deliberately built to rank, such as a "red sarees" category view; WooCommerce product filters and SEO explains that choice. Second, if filter URLs are already indexed, a robots.txt block stops Google seeing their canonical or noindex tags, so they can linger in results. Sort out canonicals first, then block.
Robots.txt blocks crawling, not indexing
This is the most misunderstood point. If other pages link to a URL you've blocked, Google can still index the bare URL without ever reading the page, and it can't see a noindex tag on a page it isn't allowed to crawl. Pick the tool that matches the goal:
| Your goal | Use | Why |
|---|---|---|
| Keep a page out of Google's results | A noindex tag, with crawling allowed | Google must crawl the page to see the noindex |
| Stop crawlers wasting time on endless URL variations | Robots.txt | This is what it is designed for |
| Keep private files or areas private | A login or password protection | Robots.txt is public and only a request |
| Keep a staging site out of Google | Password protection | A blocked staging site can still be indexed from links; see staging sites explained |
| Remove a page already in Google | Delete it (404 or 410) or noindex it, and leave it crawlable | Blocking it freezes the old version in the index |
AI crawlers and robots.txt
AI companies run their own crawlers, and robots.txt is how you opt out of the ones that respect it. User-agent names at the time of writing include GPTBot (OpenAI's training crawler), OAI-SearchBot (ChatGPT search), ClaudeBot (Anthropic), PerplexityBot, CCBot (Common Crawl) and Google-Extended, which controls whether Google may use your content for its Gemini models. Blocking Google-Extended does not remove you from Google Search, and Google treats AI Overviews as part of Search.
User-agent: GPTBot
Disallow: /
User-agent: Google-Extended
Disallow: /
Whether to block them is a business decision, not a technical one. A training crawler takes content without sending visitors; an AI search crawler is what lets assistants find and cite your pages. If you use Cloudflare, check whether its AI crawler settings add lines to your live robots.txt.
How to test your robots.txt
- Open the live file at https://example.com/robots.txt, and also try the www or non-www and http versions to confirm they redirect to the same place.
- Open the robots.txt report in Search Console, under Settings > Crawling. It shows the versions Google has fetched, when it last checked, any errors or warnings, and lets you request a recrawl after a fix. It replaced the old robots.txt Tester, which Google retired in 2023.
- Inspect your key URLs with the URL Inspection tool. Under the crawl details, "Crawl allowed?" should say Yes for every page you want in Google.
- Use Bing Webmaster Tools' robots.txt tester if you also care about Bing.
- Repeat after every launch, redesign or migration, as part of a wider check such as the WordPress technical SEO audit.
Robots.txt, noindex or a password: which one to use
Most robots.txt problems come from using it for a job another tool does better. Pick the tool by what you actually want to happen.
| What you want | Use this | Why |
|---|---|---|
| Stop crawlers wasting time on wp-admin or internal search results | robots.txt Disallow | Controls crawling, which is all you need here |
| Keep a thank-you page or thin tag archive out of Google | noindex in your SEO plugin | Google must crawl the page to see the noindex, so don't block it in robots.txt |
| Remove a page that is already indexed | noindex, or delete it with a 404 or 410 | Search Console's Removals tool only hides it temporarily |
| Hide a staging or development site | Password protection | Robots.txt is public and only a request; a password actually blocks access |
| Keep PDFs or other files out of results | X-Robots-Tag: noindex header | Files have no HTML head for a meta tag |
| Move a page to a new URL | 301 redirect | Passes visitors and signals to the new address |
Keep the robots.txt file in the same family as your XML sitemap, redirects and orphan page checks: together they decide what Google can find and crawl.
What I check on client sites: that yourdomain/robots.txt loads, has no leftover "Disallow: /", lists the right sitemap, and that Search Console's robots.txt report (Settings > robots.txt) shows no fetch errors.
When to get help
Get help when important pages show "Blocked by robots.txt" or "Indexed, though blocked by robots.txt", when a staging rule reached the live site, or when store filter URLs are eating crawl effort. WordPress SEO services covers this kind of work, with a written scope before anything starts. You can also send the details through the contact form.
FAQs
Where is robots.txt in WordPress?
Usually nowhere on disk: WordPress generates a virtual one at /robots.txt on your domain. You can edit it through Yoast's file editor or Rank Math's robots.txt setting, or create a real file in the site's root folder, which then takes over completely.
Does robots.txt stop a page from appearing in Google?
Not reliably. A blocked page can still be indexed if other pages link to it, just without a description. Use a noindex tag on a crawlable page, or delete the page, if you want it gone from results.
Should I block AI crawlers like GPTBot?
It depends on whether you mind your content being used to train AI models, and whether you want AI assistants to cite you. Blocking training crawlers while allowing AI search crawlers is a common middle ground. Google-Extended affects only Google's AI models, not your Google Search rankings.
What should a WordPress robots.txt file contain?
For most sites, just a User-agent: * line, Disallow: /wp-admin/, Allow: /wp-admin/admin-ajax.php and a Sitemap line with your full sitemap URL. Don't block CSS, JavaScript, uploads or whole folders of content.
Does "Discourage search engines" in WordPress change robots.txt?
The setting at Settings > Reading asks search engines not to index the site; current versions do this mainly with a noindex robots meta tag. Either way, make sure it is unticked on a live site and ticked on staging.
Need help with your website?
I'm a freelance WordPress developer building fast, SEO-friendly websites since 2020. Tell me what you need and I'll reply with a plan and a fixed quote, usually within 24 hours.


