Technical SEO

WordPress robots.txt: where it comes from and how to edit it safely

WordPress makes a virtual robots.txt for you. Here's what it says, how to edit it with Yoast, Rank Math, AIOSEO or a real file, and which rules to keep.

// in this article

WordPress doesn’t ship a robots.txt file. It builds one on the fly when a crawler asks for yourdomain.com/robots.txt, and you change it with an SEO plugin’s editor, a real file uploaded to your site’s root folder, or a few lines of code.

The default it builds is already safe for most sites, so the real job is usually small: add your sitemap, avoid the outdated rules older guides still recommend, and make sure nothing left over from a staging site blocks Google. This guide shows where your file is coming from, how to edit it with each method, and what to check afterward.

Where your WordPress robots.txt comes from

There are three possible sources, and only one of them answers at a time. That’s why an edit sometimes “doesn’t stick”.

A real file A robots.txt sitting in the root folder. The web server sends it before WordPress even loads. wins if present
An SEO plugin Rank Math and AIOSEO change the virtual file. Yoast's editor writes a real one. most sites
WordPress core The virtual default, built by the do_robots function when no file exists. fallback
fig 1 · the three places a wordpress robots.txt can come from, per the wordpress core source and the yoast, rank math and aioseo docs

The virtual file is made by WordPress’s do_robots() function, and every plugin that edits it does so through the robots_txt filter. A real file skips all of that. Rank Math’s own guide says that to use its editor you “need to delete the actual robots.txt file (if any) from your website’s root folder.”

What the default file says

On a public site with WordPress’s built-in sitemaps switched on, the virtual file is four lines:

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

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

The first three lines come from do_robots(). They keep crawlers out of the dashboard but let them reach admin-ajax.php, which some themes and plugins call from public pages. The Sitemap line is added by WordPress’s sitemap code, which only adds it when the site is public. If you use an SEO plugin’s sitemap instead, the line should point to that one. Yoast’s, for example, is sitemap_index.xml.

That default is fine for nearly every small business site. You only need to edit it to add a missing sitemap line, to block a specific section you don’t want crawled (internal search results, a members’ area, a staging folder on the same domain), or to set rules for particular bots.

Before you start

  • Look at the live file. Open yourdomain.com/robots.txt in a private browser window and copy what’s there, so you can put it back if something breaks.
  • Work out which source is answering. If you see # START YOAST BLOCK, a real file written by Yoast is in place. If you’ve never touched it and it matches the four lines above, it’s the virtual one. Your host’s file manager or an SFTP client will show whether a robots.txt sits next to wp-config.php.
  • Have Search Console access. You’ll want the robots.txt report to confirm Google fetched the new version. If you aren’t set up yet, see how to add a user to Google Search Console.
  • Know where WordPress lives. Crawlers only read the file at the top level of the host. If WordPress is installed in a subfolder such as /blog/, the rules must go in a real file at the domain root, not in WordPress.

How to edit robots.txt in WordPress, step by step

  1. Pick one method and stick to it. Use your SEO plugin’s editor if you have one. Use a real file only if you have no SEO plugin, or your host blocks the virtual file. Mixing the two is the main reason edits vanish.
  2. Yoast SEO: go to Yoast SEO, then Tools, then File editor, and click the button to create the file. Yoast’s help page notes the File editor doesn’t appear if file editing is disabled in your WordPress install, and saving can fail if the file isn’t writable. In that case use your host’s file manager.
  3. Rank Math: turn on Advanced Mode (top right of the Rank Math dashboard), then open General Settings and Edit robots.txt. Delete any real robots.txt from the root folder first, or your changes won’t show.
  4. All in One SEO: go to All in One SEO, then Tools, and switch on Enable Custom Robots.txt. AIOSEO’s docs say it stores your rules in the database and adds them to the WordPress default rather than writing a file.
  5. No plugin: create a plain text file named robots.txt, paste in your rules, and upload it to the folder that holds wp-config.php (often public_html). It replaces the virtual file completely, so include the sitemap line yourself.
  6. Developers: add a robots_txt filter in a small custom plugin rather than the theme, so the rules survive a theme change. The filter receives the current output and a flag saying whether the site is public.
  7. Save, then reload the live file in a private window. If your site uses page caching or a CDN, purge the cache for /robots.txt before you check.
  8. Ask Google to recheck. In Search Console, open Settings, then the robots.txt report, and request a recrawl. Google usually caches the file for up to 24 hours, so without that it can take a day to see the change.

Step 1 matters most. A real file in the root folder always beats the plugin, so if you edit in Rank Math while an old file sits on the server, the screen says one thing and Google reads another.

Safe rules for a WordPress site

Keep the file short. Yoast’s own robots.txt guidance says the old habit of blocking wp-includes and the plugins folder “is no longer valid”, because Google renders pages with their CSS and JavaScript. Google’s robots.txt introduction puts it plainly: if missing resources make a page harder to understand, “don’t block them.”

✕ Copied from a 2014 tutorial
User-agent: *
Disallow: /wp-includes/
Disallow: /wp-content/plugins/
Disallow: /wp-content/themes/
Noindex: /appointments/
result: css and scripts blocked, noindex ignored, no sitemap
✓ Cleaned up
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=
Sitemap: https://example.com/sitemap_index.xml
result: pages render, search results skipped, sitemap found
fig 2 · a made-up vet clinic's wordpress robots.txt before and after, following yoast's and google's guidance

A few rules worth knowing:

  • Internal search. Disallow: /?s= stops crawlers wandering through endless search result pages. It’s optional, and only worth adding if you see those URLs in Search Console.
  • Use full URLs for sitemaps. Sitemap: https://yourdomain.com/sitemap_index.xml, not a relative path. You can list more than one.
  • No noindex lines. Google ignores them. To keep a page out of results, use a noindex tag on the page instead, as covered in robots.txt noindex.
  • AI crawlers. Rules for GPTBot, ClaudeBot and the rest go in the same file. Which ones to block is its own decision, covered bot by bot in should you block AI crawlers in robots.txt.

What “Discourage search engines” does now

Settings, then Reading, has a box labelled “Discourage search engines from indexing this site”. Many guides say it adds Disallow: / to robots.txt. It used to. WordPress removed that rule in version 5.3 (2019) and now adds a noindex, nofollow robots meta tag to every page instead. You can see it in the current core source.

That change is better for you. With the box ticked, Google can still crawl the pages and see the noindex tag, so they stay out of results. But it means checking robots.txt alone won’t tell you a site is hidden. When a new site isn’t getting indexed, look at this box first, then the steps in how to get a website indexed.

step_01 Box ticked during the build Every page gets a noindex, nofollow meta tag.
step_02 robots.txt looks normal Since 5.3 there's no Disallow: / to warn you. easy to miss
step_03 Untick at launch Settings, then Reading. The tag disappears from every page.
step_04 Check one page View source on the home page and search for noindex before you submit the sitemap.
fig 3 · how the discourage search engines box behaves since wordpress 5.3, per the core dev note

What can go wrong

  • Your edit doesn’t show up. A real file in the root folder is overriding the plugin, or a cache is serving the old version. Check the server for a file, then purge the page cache and CDN.
  • A Disallow: / survives from staging. Developers sometimes block a staging copy with a real file, then move the whole folder to the live site. One line hides everything. The robots.txt report in Search Console will show it. Our disallow all guide covers the fix and the wait that follows.
  • Rules block CSS or JavaScript. Old rules on /wp-includes/ or /wp-content/ stop Google from rendering pages the way visitors see them. Delete them, then run a page through URL Inspection to check it renders.
  • The file returns a server error. Google treats a 5xx on robots.txt seriously: for the first 12 hours it stops crawling the site, then falls back to the last copy it cached. A security plugin or firewall blocking bots on /robots.txt can cause this.
  • A blocked page stays in Google. Robots.txt stops crawling, not indexing. Google says a blocked URL can still be indexed if other pages link to it, and it shows with no description.

To try a rule before it goes live, test it against your important URLs with Google’s parser, as shown in our robots.txt tester guide.

FAQ

Where is the robots.txt file in WordPress?

Usually nowhere on disk. WordPress generates it when someone requests yourdomain.com/robots.txt. If a real file exists, it’s in the root folder next to wp-config.php, and it takes priority over the generated one.

Do I need to edit robots.txt on a new WordPress site?

Often not. The default already blocks the dashboard and, with WordPress’s built-in sitemaps on, lists the sitemap. Check that the sitemap line points to the sitemap you actually use, and that “Discourage search engines” is unticked.

Should I block wp-content or wp-includes?

No. Those folders hold the CSS, JavaScript and images Google needs to render your pages. Yoast calls blocking them an outdated practice, and Google advises against blocking resources a page depends on.

Leave the WordPress default mostly alone

The best WordPress robots.txt is usually the one you didn’t write: the dashboard blocked, admin-ajax allowed, and a correct sitemap line. Edit it through one method only, never block the folders your pages need to render, and use noindex, not robots.txt, for anything you want out of Google. After any change, reload the file, purge the cache and ask Search Console to fetch it again.

Portrait of Liam Fraser
// written byLiam FraserSEO specialist with 3 years of experience. Liam writes about what works in local, technical and AI search.About SerpSurfers →