SEO

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.

Robots.txt for WordPress: Default File, How to Edit It, Best Example
On this page
  1. How robots.txt works
  2. The syntax, line by line
  3. A safe robots.txt for WordPress
  4. WordPress sitemap XML and robots.txt
  5. Robots.txt WordPress setups: good, risky and broken
  6. Robots.txt for WooCommerce stores
  7. Robots.txt blocks crawling, not indexing
  8. AI crawlers and robots.txt
  9. How to test your robots.txt
  10. Robots.txt, noindex or a password: which one to use
  11. When to get help
  12. FAQs
Key takeaways
  • 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

LineWhat it doesExample
User-agentNames the crawler the following rules apply to; * means all crawlersUser-agent: Googlebot
DisallowA path the crawler should not requestDisallow: /wp-admin/
AllowAn exception inside a disallowed pathAllow: /wp-admin/admin-ajax.php
SitemapThe full URL of your XML sitemap; can appear anywhere in the fileSitemap: 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:

SetupXML sitemap address
No SEO plugin (WordPress core)/wp-sitemap.xml
Yoast SEO or Rank Math/sitemap_index.xml
Other SEO or sitemap pluginsCheck 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 containsVerdictWhy
Disallow: /wp-admin/, Allow: /wp-admin/admin-ajax.php, Sitemap lineGoodThe WordPress default plus your sitemap; nothing useful is blocked
Disallow: /wp-content/ or /wp-includes/RiskyBlocks CSS, JavaScript and images Google needs to render pages
Disallow: /*? on a storeRiskyCan block paginated, filtered or tracked URLs you want crawled
Disallow: / for User-agent: *BrokenBlocks the whole site, usually left over from a staging copy
Sitemap line pointing to an old domain or httpBrokenSends 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 goalUseWhy
Keep a page out of Google's resultsA noindex tag, with crawling allowedGoogle must crawl the page to see the noindex
Stop crawlers wasting time on endless URL variationsRobots.txtThis is what it is designed for
Keep private files or areas privateA login or password protectionRobots.txt is public and only a request
Keep a staging site out of GooglePassword protectionA blocked staging site can still be indexed from links; see staging sites explained
Remove a page already in GoogleDelete it (404 or 410) or noindex it, and leave it crawlableBlocking 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

  1. 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.
  2. 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.
  3. 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.
  4. Use Bing Webmaster Tools' robots.txt tester if you also care about Bing.
  5. 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 wantUse thisWhy
Stop crawlers wasting time on wp-admin or internal search resultsrobots.txt DisallowControls crawling, which is all you need here
Keep a thank-you page or thin tag archive out of Googlenoindex in your SEO pluginGoogle must crawl the page to see the noindex, so don't block it in robots.txt
Remove a page that is already indexednoindex, or delete it with a 404 or 410Search Console's Removals tool only hides it temporarily
Hide a staging or development sitePassword protectionRobots.txt is public and only a request; a password actually blocks access
Keep PDFs or other files out of resultsX-Robots-Tag: noindex headerFiles have no HTML head for a meta tag
Move a page to a new URL301 redirectPasses 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.

Found this useful? Share it:
Contact

Let's build your next website

Available for freelance projects, agency white-label work and long-term maintenance. Feel free to pass this along to your team or company.

I reply within 24 hours, usually the same day. Your details are emailed to me, then WhatsApp opens so we can chat right away.

Chat now