/ โ† Robots and Sitemap Fixes / Edit robots.txt in WordPress
In this guide
  1. Where a WordPress robots.txt comes from
  2. How to find out what is serving your file
  3. Editing it in Yoast SEO and Rank Math
  4. Editing the file directly
  5. How Cloudflare can change robots.txt
  6. A sensible WordPress robots.txt
  7. A worked example
  8. The fix, step by step
  9. Edge cases worth knowing
  10. Keeping it fixed
  11. Questions and answers

Where a WordPress robots.txt comes from

WordPress does not ship with a robots.txt file. When a request for /robots.txt reaches WordPress and no real file exists, WordPress builds one on the fly. This is the virtual robots.txt. Plugins can change the virtual file through a filter, and a CDN can change the response again on its way to the visitor. The order of precedence is what matters:

SourceWhere it livesWhen it wins
Physical filerobots.txt in the site root, next to wp-config.phpAlways, if it exists. The web server serves it before WordPress runs.
SEO plugin rulesSaved in the database and added to the virtual fileOnly when there is no physical file
WordPress coreGenerated by WordPressWhen there is no physical file and nothing else changes it
Cloudflare additionsCloudflare's edgeAdded on top of whichever version the origin sends, if the setting is on

The default virtual file in current WordPress looks like this, with the Sitemap line pointing at the core sitemap unless an SEO plugin replaces it with its own:

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

Sitemap: https://www.example.com/wp-sitemap.xml
๐Ÿ’ก A quick way to tell which source is live: a physical file appears in the site root when you list it by SFTP or in the file manager. If there is no file there but /robots.txt loads, WordPress or a plugin is generating it.

How to find out what is serving your file

Open https://www.example.com/robots.txt in a private window, then check from the command line so caches in your browser do not mislead you:

curl -s https://www.example.com/robots.txt
curl -sI https://www.example.com/robots.txt | grep -iE "^(server|cf-cache-status|age|last-modified|x-powered-by)"

Clues in the headers:

If you have shell access, the definitive check is whether the file exists in the root:

ls -l /var/www/vhosts/example.com/httpdocs/robots.txt

That path is the Plesk default; on other hosts it is the folder that contains wp-config.php. Compare the file's contents with what the site serves. If they match, the physical file is in charge. If they differ, something between the file and the visitor is changing it, most often a CDN or a cache. If you see rules you did not expect, the robots.txt blocks guide explains how to tell which ones are doing harm.

Editing it in Yoast SEO and Rank Math

Yoast SEO

Go to Yoast SEO, then Tools, then File editor. If no robots.txt exists, Yoast offers a button to create one; it writes a real file to the site root, which then overrides the virtual file. Edit the text and save. If the File editor option is missing, file editing has been switched off on the site, usually by define( 'DISALLOW_FILE_EDIT', true ); in wp-config.php or by your host, or the folder is not writable. In that case upload the file by SFTP instead. Leave the protection in place; it exists for good security reasons.

Rank Math

Rank Math's editor is under Rank Math, then General Settings, then Edit robots.txt, and the menu item may only show in Advanced Mode. Rank Math does not write a file. It stores your text and serves it as the virtual robots.txt. That has one consequence that catches many people: if a physical robots.txt exists, the box is greyed out and Rank Math shows a notice. Rename or delete the physical file by SFTP and the editor unlocks.

Using a code filter instead

Without an SEO plugin, you can add to the virtual file from a small plugin or your child theme's functions.php:

add_filter( 'robots_txt', function ( $output, $public ) {
    $output .= "Disallow: /?s=\n";
    $output .= "Disallow: /search/\n";
    return $output;
}, 20, 2 );

This only affects the virtual file, so it does nothing if a physical file exists. Use one method only. A physical file, a plugin and a filter all trying to set the same file is the usual reason for confusion. For the wider WordPress picture, including sitemaps, see robots.txt and sitemaps in WordPress.

Editing the file directly

Without a plugin, create a plain text file named robots.txt, all lower case, in the site root. Use a text editor rather than a word processor so no formatting is added. Save as UTF-8, with one rule per line. Upload it by SFTP or through your hosting file manager; in Plesk that is Files, then the httpdocs folder for the main domain.

On the server, editing in place avoids a download and re-upload:

sudo nano /var/www/vhosts/example.com/httpdocs/robots.txt
sudo chown siteuser:psacln /var/www/vhosts/example.com/httpdocs/robots.txt
sudo chmod 644 /var/www/vhosts/example.com/httpdocs/robots.txt

Replace siteuser with the subscription's system user. The file must be readable by the web server, or it returns 403, which Google treats as no rules. On nginx, check that /robots.txt is allowed to fall through to WordPress when no file exists. Some configurations serve it only as a static file, so the virtual file returns 404 and plugin edits never appear:

location = /robots.txt {
    try_files $uri $uri/ /index.php?$args;
    access_log off;
}

How Cloudflare can change robots.txt

Cloudflare can do two things to the file. The first is caching: plain text files are among the types Cloudflare caches by default, so after an edit the edge may keep serving the old copy until it expires or you purge it. In the dashboard, go to Caching, then Configuration, and use Custom Purge to purge the exact address https://www.example.com/robots.txt, plus the non-www version if it serves its own file.

The second is adding content. Cloudflare offers a managed robots.txt option, found with its bot and AI crawler settings, which adds Cloudflare's own lines to your file, such as rules telling known AI training crawlers not to crawl. If your live file contains lines you never wrote, especially near the top, check that setting before searching WordPress for them. Turn it off if you prefer to manage every line yourself, or keep it and write your own rules around it.

Remember that robots.txt is a request, not a lock. Well-behaved crawlers follow it; others ignore it. To actually stop unwanted bots, use firewall rules, and to decide which AI crawlers to allow, see fixing robots.txt AI blocks.

A sensible WordPress robots.txt

Most WordPress sites need very little. This is a good starting point:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /?s=
Disallow: /search/

Sitemap: https://www.example.com/sitemap_index.xml

The search lines stop crawlers wasting time on internal search results, which can produce endless thin URLs. Use the sitemap address your setup actually serves: /sitemap_index.xml for Yoast and Rank Math, /wp-sitemap.xml for WordPress core.

โš ๏ธ Do not block /wp-content/ or /wp-includes/. Search engines need the CSS, JavaScript and images in those folders to render your pages. Blocking them can make pages look broken to Google and harm how they are assessed.

Never use robots.txt to remove a page from Google. It stops crawling, not indexing, and a blocked page can still appear in results with no description. To keep a page out, leave it crawlable and add noindex, as the noindex and disallow guide explains.

A worked example

An owner manages robots.txt in Rank Math. After restoring the site from a backup, they want to add Disallow: /?s=, but the live file no longer matches anything in Rank Math, and the editor box is now greyed out. Clearing the browser cache and purging the caching plugin make no difference.

Listing the site root by SFTP shows an old robots.txt written years earlier by a plugin that has since been removed, brought back by the backup. The web server serves that file before WordPress ever runs, so Rank Math's virtual version never reaches anyone. The owner renames the old file to robots-old.txt, purges /robots.txt in Cloudflare, and reloads. Rank Math's version appears at once, including the new rule.

The lesson is to check the site root after any restore or migration. A stray physical file is invisible from the WordPress dashboard, yet it decides what every crawler reads.

The fix, step by step

Step 1

Load the live file and check its source

Open /robots.txt in a private window and with curl -s, then list the site root by SFTP or the hosting file manager. If a robots.txt file exists in the root, that file is what visitors get, and plugin settings are ignored. If no file exists, WordPress or a plugin is generating it. Check the cf-cache-status header too. Write down which source is live before editing anything, so you change the right one first time.

Step 2

Choose one place to manage it

Decide whether you will manage robots.txt through a plugin or as a physical file, and remove the other. If you want to use Rank Math or a code filter, rename an old physical file to robots-old.txt so the virtual file can show. If you prefer a physical file, leave the plugin's robots settings alone. One source of truth prevents the most common problem, which is edits that never appear on the live site.

Step 3

Edit in Yoast SEO

In Yoast SEO, open Tools, then File editor. Create the file if Yoast offers to, edit the rules and save. Yoast writes a physical file to the site root. If the File editor option is missing, file editing is disabled by DISALLOW_FILE_EDIT or the root is not writable, so upload the file by SFTP instead. Reload /robots.txt to confirm the saved text appears exactly as you typed it, with no leftover rules.

Step 4

Edit in Rank Math

In Rank Math, switch to Advanced Mode if needed, then open General Settings and Edit robots.txt. Type the rules and save. Rank Math serves them as the virtual file, so the box is locked when a physical robots.txt exists; rename that file first. Reload /robots.txt and check that Rank Math's text appears. If nothing changes on nginx, check the location = /robots.txt block passes requests to index.php when no file exists.

Step 5

Or edit the physical file

Without a plugin, create a plain UTF-8 text file called robots.txt in the folder that holds wp-config.php, with one rule per line. Edit it in place on the server with sudo nano, or upload it by SFTP or the file manager. Set it to 644 and owned by the site user, so the web server can read it. Load the file in a browser and confirm the status is 200 and the content is yours.

Step 6

Check Cloudflare's settings

If the live file contains lines you did not write, open the Cloudflare dashboard and look at the managed robots.txt option among the bot and AI crawler settings. Turn it off if you want full control, or keep it and add your rules around it. Then compare the file served through Cloudflare with the file on the origin. When they match apart from the managed lines, Cloudflare is behaving as intended.

Step 7

Purge every cache

Purge /robots.txt in your caching plugin, in any server cache, and in Cloudflare using Custom Purge with the exact address. Purge each host that serves its own copy, such as the www and non-www versions. Then run curl -sI and check that cf-cache-status shows a miss or the age has reset. Without this step, visitors and crawlers can keep receiving the old file for hours after your edit.

Step 8

Confirm Google has the new version

Open the robots.txt report under Settings in Google Search Console. Check the fetch date and status for your host, and request a recrawl if the date is from before your edit. Google generally refreshes its copy within a day anyway. Once the report shows a successful fetch after your change, the new rules are in effect for Google. Run URL Inspection on a page you meant to allow to confirm it is not blocked.

Edge cases worth knowing

Keeping it fixed

Pick one source and stick with it: a plugin's virtual file or a physical file, not both. Write down which one you use somewhere your team will find it. After every change, load the live file with curl, purge the CDN copy, and check the robots.txt report under Settings in Search Console, which shows when Google last fetched the file and whether the fetch worked. If the file ever fails to load, the robots.txt unreachable guide explains why that is urgent.

Questions and answers

1. Where is the robots.txt file in WordPress?

By default there is no robots.txt file in WordPress; WordPress generates a virtual one whenever someone requests the address. That is why you will not find it by SFTP on a fresh site. If a physical file exists, it sits in the site root, the folder that contains wp-config.php, and it overrides the virtual file. SEO plugins either write that physical file, as Yoast does, or change the virtual file, as Rank Math does, depending on the plugin.

2. Why is my robots.txt not updating in WordPress?

The usual reason is that you edited one source while another is being served, most often a plugin setting when a physical robots.txt file in the site root overrides it. Caching is the second most common reason: a caching plugin, server cache or Cloudflare may still be serving the old copy. List the site root by SFTP to look for a physical file, purge the address in every cache layer, then reload the live file with curl to see what is really being served.

3. Why is the Rank Math robots.txt editor greyed out?

The Rank Math robots.txt editor is greyed out because a physical robots.txt file already exists in your site root. Rank Math edits the virtual file that WordPress generates, and the web server always serves a real file first, so Rank Math locks the box to avoid edits that would never appear. Rename or delete the physical file by SFTP or your hosting file manager, reload the settings page, and the editor becomes available.

4. Why does Cloudflare add text to my robots.txt?

Cloudflare adds text to robots.txt when its managed robots.txt option is switched on, which inserts Cloudflare's own lines, such as rules asking AI training crawlers not to crawl. These lines are added at the edge, so you will not find them in WordPress or on your server. Check the option among the bot and AI crawler settings in your Cloudflare dashboard, and turn it off if you want to write every line yourself, then purge the cached file.

5. Should I block wp-content in robots.txt?

No, you should not block wp-content or wp-includes in robots.txt. Those folders hold the stylesheets, scripts, fonts and images that search engines need to render your pages as visitors see them. Blocking them can make pages appear broken to Google and can affect how they are assessed. Older advice recommended blocking them, but that dates from before Google rendered pages fully. A sensible WordPress file blocks wp-admin, allows admin-ajax.php and lists your sitemap.

6. Can I use robots.txt to remove a page from Google?

No, robots.txt stops crawling, not indexing, so it is the wrong tool for removing a page. A page blocked in robots.txt can still appear in search results if other pages link to it, usually without a description. To remove a page, keep it crawlable and add a noindex robots meta tag, or delete it so it returns 404 or 410. For urgent cases, the Removals tool in Search Console hides a URL temporarily while the permanent fix takes effect.

7. What should a WordPress robots.txt contain?

A typical WordPress robots.txt needs only a few lines: a User-agent line for all crawlers, a Disallow for /wp-admin/, an Allow for /wp-admin/admin-ajax.php, and a Sitemap line with the full address of your sitemap. You can add Disallow lines for internal search results to stop crawlers wasting time on them. Avoid blocking theme or plugin folders, and add other rules only when you know a specific path should not be crawled.

Check what your live robots.txt really says

The robots and sitemap checker on aiwebpageseo.com fetches your live robots.txt, shows every rule and Sitemap line it contains, and flags rules that block pages or files search engines need.

Open Robots and Sitemap Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Robots and Sitemap Fixes  ·  robots.txt unreachable, 404, 403 or 500  ·  Robots.txt and sitemaps in WordPress  ·  sitemap_index.xml not working in WordPress  ·  How to fix robots.txt syntax  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.