WordPress

How to Manually Overwrite Robots.txt File in WordPress?

Upload a plain robots.txt to your WordPress root and it overrides the virtual file. Why plugin edits stop working, the robots_txt filter, and how to test.

Shashank Dubey
·13 min read
Flow diagram: a request for robots.txt is served from a real file on disk if one exists, otherwise WordPress builds a virtual file

To manually overwrite robots.txt in WordPress, upload a plain text file named robots.txt to the folder that holds your site’s index.php (usually public_html), then load https://yoursite.com/robots.txt to confirm the server now returns your file. That works because WordPress has no robots.txt on disk by default. It answers the request with a virtual file built in PHP, and the web server only hands the request to WordPress when no real file exists at that path. A real file always wins.

That last point is also why so many people get stuck. Once a physical file is on the server, the robots.txt editors in Yoast SEO, Rank Math and other plugins stop having any effect, and changes made through the robots_txt filter vanish. This guide covers both routes: replacing the file by hand, and changing the virtual file without one. We checked every function, rewrite rule and filter against the WordPress core source (trunk, 7.2 RC1) and Google’s robots.txt documentation on 18 November 2026.

Search Console has not recorded any queries for this page yet, so the headings below follow the questions people ask when their robots.txt edits do not stick.

Where is the robots.txt file in WordPress?

On a fresh install, nowhere. There is no robots.txt file in the WordPress download, and nothing writes one to disk. When a crawler asks for /robots.txt, the request goes through WordPress like any other URL, matches a rewrite rule, and the do_robots() function in wp-includes/functions.php prints the response.

The chain in core looks like this:

  1. The rewrite rule robots\.txt$ maps the URL to index.php?robots=1. WordPress only adds that rule when the site’s home URL has no path, so it is skipped for a site that lives at example.com/blog/.
  2. The rule belongs to the pretty permalink rules. With Settings > Permalinks set to Plain, WordPress generates no rewrite rules at all, so /robots.txt usually returns the web server’s 404. The query string /?robots=1 still works, because robots is a public query variable.
  3. template-loader.php sees is_robots() and fires the do_robots action, which core hooks to do_robots().
  4. do_robots() sends a text/plain header, fires the do_robotstxt action, builds the default rules and passes them through the robots_txt filter before printing.

So when someone asks where the file is, the honest answer is that it is generated on each request. If you open your site root over SFTP and find a robots.txt there, a person, a plugin or a host put it there.

What does the default WordPress robots.txt contain?

For a public site at the domain root with core sitemaps enabled, the virtual file is three rules and a sitemap line:

# Default virtual robots.txt, WordPress 7.x (checked on 18 Nov 2026)
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

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

Each line has a source in core:

Line

Where it comes from

User-agent: *

Hard-coded in do_robots().

Disallow: /wp-admin/

The path of admin_url(), so it follows a custom admin path if a plugin changes it.

Allow: /wp-admin/admin-ajax.php

The path of admin_url( 'admin-ajax.php' ). Themes and plugins call this file from the front end, so crawlers need it to render pages.

Sitemap: ...wp-sitemap.xml

Added by WP_Sitemaps::add_robots() on the robots_txt filter at priority 0, only when the site is public. Present since WordPress 5.5.

SEO plugins usually change this output through the same filter. Yoast SEO, for example, swaps the core sitemap URL for its own sitemap_index.xml and can add rules for internal search URLs. If your live file looks different from the block above and there is no file on disk, a plugin is filtering it.

Why does a physical robots.txt override WordPress and SEO plugins?

Because the web server checks the disk before it ever runs PHP. The standard WordPress block in .htaccess on Apache sends a request to index.php only when no real file or folder matches:

# BEGIN WordPress (standard rules, checked on 18 Nov 2026)
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

The !-f condition means “not an existing file”. Put a robots.txt in the root and Apache serves it directly. Nginx behaves the same way with the usual try_files $uri $uri/ /index.php?$args; line: $uri is tried first, and only a miss falls through to WordPress. If you are tidying other root-level rules at the same time, our notes on WordPress .htaccess rules show how the WordPress block sits next to caching and security rules.

The practical result: when a real file exists, nothing inside WordPress runs for that URL. The robots_txt filter, the sitemap line, Rank Math’s editor and every plugin setting that adds a rule are all ignored. Rank Math says this plainly in its knowledge base: its file is virtual, and a physical file in the root stops you editing it from the dashboard.

Yoast SEO works differently. Its File editor under Yoast SEO > Tools creates and edits a real robots.txt on disk (the menu is hidden when file editing is disabled for the install), so after using it you have a physical file, with the same override effect.

How do I manually overwrite robots.txt in WordPress?

Six steps. The first two take a minute and save most of the confusion people run into later.

1. Look at what is being served now

Fetch the live file and its headers. Do it from the command line rather than a browser, so a cached copy in your browser does not fool you:

# checked on 18 Nov 2026
curl -sI https://example.com/robots.txt
curl -s  https://example.com/robots.txt

A 200 with Content-Type: text/plain; charset=utf-8 and the three default lines means WordPress is answering. Anything else (a 404, a redirect to the homepage, an HTML page) tells you to fix routing before you write rules, which the troubleshooting section below covers.

2. Check whether a file already exists, and back it up

Find the folder that serves your home URL. On most hosts that is the folder with wp-config.php and index.php. With WP-CLI on the server:

# checked on 18 Nov 2026 (WP-CLI 2.12.0)
cd /path/to/wordpress
wp option get home
ls -la robots.txt 2>/dev/null && cp robots.txt robots.txt.bak-$(date +%F)

If WordPress sits in its own subfolder but the site runs from the domain root (the “Giving WordPress its own directory” setup), the robots.txt goes in the folder that serves the domain root, next to the small index.php that loads WordPress, not inside the core folder.

3. Start from the current output, then edit

Copy what the site serves today into a local file, so you keep the sitemap line and any rules your SEO plugin was adding. Then make your changes. A sensible base for most WordPress sites:

# robots.txt for example.com (edited 18 Nov 2026)
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

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

Use the sitemap URL your site actually serves. With Yoast SEO active that is /sitemap_index.xml; Rank Math also uses /sitemap_index.xml; core alone uses /wp-sitemap.xml. Open it in a browser before you paste it in.

4. Save it correctly

Google’s robots.txt specification asks for a UTF-8 plain text file with one rule per line, and ignores everything after 500 KiB. Save with a plain text editor (not a word processor), name it exactly robots.txt in lower case, because the URL is case-sensitive, and keep the .txt extension visible so you do not end up with robots.txt.txt.

5. Upload it to the root

Any of these works:

  • SFTP: connect, open the web root, upload the file.
  • Host file manager: cPanel, Plesk and most managed hosts have one. Upload, or create a new file and paste.
  • SSH: write it in place with a heredoc and set normal permissions.
# checked on 18 Nov 2026
cat > robots.txt <<'TXT'
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

Sitemap: https://example.com/wp-sitemap.xml
TXT
chmod 644 robots.txt

Some managed hosts block writes to the web root or regenerate robots.txt themselves. If your upload disappears, ask the host before trying again.

6. Confirm the server returns your file

Run the same curl commands from step 1. The body should match your file exactly. If it still shows the old rules, a cache is in the way: purge your page cache plugin, the host cache and any CDN. A robots.txt served through a full-page cache can stick for hours. Our breakdown of WordPress caching layers lists where each one lives and how to clear it.

What should a WordPress robots.txt file contain?

Less than most templates suggest. Google’s own introduction to robots.txt says the file is mainly for managing crawler traffic, and that it is not a way to keep a page out of Google. For most WordPress sites the default plus a correct sitemap line is the right file. Add rules only for URLs that waste crawling and have no value in search.

Rule

Use it?

Why

Disallow: /wp-admin/

Yes (default)

Nothing in the admin should be crawled.

Allow: /wp-admin/admin-ajax.php

Yes (default)

Front-end features call it; blocking it can break how Google renders the page.

Disallow: /wp-content/ or /wp-includes/

No

These hold the CSS, JavaScript and images Google needs to render your pages.

Disallow: /*?add-to-cart= (stores)

Often

Add-to-cart links are endless URL variants with no search value.

Disallow: /?s= and /search/

Optional

Core already adds noindex to search results. Blocking them stops Google seeing that tag, so pick one approach.

Crawl-delay

No for Google

Google ignores it. Its spec lists only user-agent, allow, disallow and sitemap.

Disallow: / for User-agent: *

Only on staging

It stops all compliant crawling. The most expensive line to leave in by mistake.

Two rules from the spec decide which line wins when rules overlap. A crawler obeys only the most specific User-agent group that matches it and ignores the rest, so a separate User-agent: Googlebot group means Googlebot skips everything under User-agent: *. Inside a group, the longest matching path wins, and when an allow and a disallow are equally specific, Google picks the less restrictive allow. The wildcards * (any characters) and $ (end of URL) are supported.

Blocking AI crawlers is a common reason to edit the file in 2026. Rules like User-agent: GPTBot followed by Disallow: / are requests, not locks. Well-behaved bots honour them, and plenty of scrapers that borrow a real bot’s name do not, which is what our guide to verifying crawlers that claim to be ClaudeBot is about.

Can I change robots.txt in WordPress without creating a file?

Yes, and on most sites it is the better choice, because the sitemap line and plugin rules keep working. You have two options.

Use the robots_txt filter in a small plugin

A must-use plugin survives theme changes and cannot be switched off by accident. This one adds a rule inside the default User-agent: * group, above the sitemap line:

<?php
// wp-content/mu-plugins/robots-extra.php (checked on 18 Nov 2026, php -l clean)
add_filter( 'robots_txt', function ( $output, $is_public ) {
	if ( ! $is_public ) {
		return $output; // Leave non-public sites alone.
	}

	$extra = "Disallow: /*?add-to-cart=\n";

	// Keep the rule inside core's "User-agent: *" group, above the Sitemap line.
	$pos = strpos( $output, "\n\nSitemap:" );
	if ( false === $pos ) {
		return $output . $extra;
	}
	return substr_replace( $output, $extra, $pos + 1, 0 );
}, 20, 2 );

We ran it against the default core output and against output with no sitemap line, and both produced a valid group. The second parameter mirrors the “Search engine visibility” setting, so the rule stays out of a site that is set to discourage search engines. Priority 20 runs after core adds the sitemap line at priority 0 and after most SEO plugins at the default 10.

Use your SEO plugin’s editor

  • Rank Math: Rank Math SEO > General Settings > Edit robots.txt. Virtual, so it is disabled when a physical file exists.
  • Yoast SEO: Yoast SEO > Tools > File editor. It writes a real file, so afterwards you are on the manual route.
  • All in One SEO: its Robots.txt editor sits under its Tools menu and filters the virtual file.

Pick one owner for the file. Two plugins filtering robots.txt, or a plugin plus a physical file, is the setup behind most of the forum threads in the mistakes section below.

Method

Survives plugin changes

Keeps the core sitemap line

Best for

Physical file in the root

Yes

No, add it by hand

Hosts where PHP is slow, or rules you want outside WordPress

robots_txt filter (mu-plugin)

Yes

Yes

Developers who want rules in version control

SEO plugin editor (virtual)

No, tied to the plugin

Plugin’s own sitemap

Site owners who prefer the dashboard

Why is my robots.txt not updating or returning 404 in WordPress?

Work down this list in order. Each check takes under a minute.

  1. A physical file exists. Covered above: the file on disk wins over every setting. Delete or rename it if you want the virtual file back.
  2. Permalinks are set to Plain. No rewrite rules means no robots.txt route. Choose any other structure and save. Then run wp rewrite list --match=/robots.txt; it should print the robots\.txt$ rule.
  3. WordPress is installed in a subfolder. Core only adds the rule when the home URL has no path, and crawlers only read robots.txt from the root of the host. Put a real file at the domain root.
  4. Nginx intercepts the URL. Many server templates include a block like location = /robots.txt { allow all; log_not_found off; access_log off; }. It has no fallback to PHP, so with no file on disk you get a 404. Add try_files $uri $uri/ /index.php?$args; inside that block and reload Nginx.
  5. A cache serves an old copy. Page cache plugins, host caches and CDNs can all hold robots.txt. Purge them, then test with curl.
  6. The CDN adds its own lines. Cloudflare’s managed robots.txt prepends AI crawler directives and a content signals block when Bot Preference Sync is on and at least one crawler policy is set to block. Your origin file is unchanged, but the response crawlers see is longer.

For the Nginx case, the corrected block looks like this:

# checked on 18 Nov 2026
location = /robots.txt {
    try_files $uri $uri/ /index.php?$args;
    access_log off;
    log_not_found off;
}

Run nginx -t before reloading so a typo does not take the site down.

Does “Discourage search engines” change robots.txt?

Not since WordPress 5.3. Older versions answered robots.txt with Disallow: / when Settings > Reading > Search engine visibility was ticked. The core announcement from September 2019 explains the change: a disallow rule stops crawlers from ever fetching the page, so they never see a noindex tag, and the URL can still end up in results. Since 5.3 the setting adds noindex to the robots meta tag on every page instead, and the core source still says so in the do_robots() docblock.

Two effects people do not expect. The sitemap line disappears from the virtual file while the setting is on, because core only adds it for public sites. And if you want a staging site kept out of crawlers entirely, the setting alone is not enough for bots that ignore meta tags; password protection is the reliable option, which Google also recommends.

When you launch, check both: untick the setting, and confirm there is no leftover staging robots.txt with Disallow: / sitting in the root.

Does robots.txt stop a WordPress page from being indexed?

No. Robots.txt controls crawling. Google states that a disallowed URL can still be indexed if other pages link to it, and Search Console reports these as “Indexed, though blocked by robots.txt”. Because Googlebot cannot fetch the page, it cannot see a noindex tag on it either.

To remove a page from results, let it be crawled and give it noindex (through your SEO plugin’s per-post setting, or the wp_robots filter in core), or put it behind a password. Only after it has dropped out of the index does a disallow rule make sense, if you still want to save crawl activity.

Robots.txt is also not a security control. Listing /private-files/ in it tells everyone where to look. The same goes for exposed folders: if your server shows a file list for /wp-content/uploads/, fix that at the server, as in our guide to turning off directory indexing, not with a disallow line.

How do I test robots.txt after editing it?

Use three checks, from quickest to most authoritative.

  1. Fetch it raw. curl -s https://example.com/robots.txt shows exactly what a crawler receives, after every server and CDN layer.
  2. Read the Search Console robots.txt report. The old robots.txt Tester is gone. Google’s robots.txt report shows which robots.txt files Google found for the top 20 hosts on your site, when it last fetched them, and any warnings or errors. It also lets you request a recrawl of the file in an emergency. The report is only available for domain-level properties.
  3. Inspect one important URL. URL Inspection in Search Console tells you whether a specific page is blocked by robots.txt.

Expect a delay. Google generally caches robots.txt for up to 24 hours, longer if it cannot refresh it. If the file returns a 5xx error, Google stops crawling for the first 12 hours while retrying, then uses the last good copy for up to 30 days. A 4xx (other than 429) is treated as if no file existed, which means no restrictions at all. Getting the file to return a clean 200 matters more than any single rule in it.

Common mistakes people report

These come up again and again in the WordPress.org support forums. Each link goes to a real thread; we paraphrased the problem and the fix. Checked on 18 November 2026.

  • Plugin setting saved, robots.txt unchanged. A Yoast SEO user enabled the option to stop crawling of internal search URLs and saw no change. They found the cause themselves: a robots.txt already existed, and Yoast only writes its block when it creates the file. (WordPress.org forum, April 2023)
  • Deleting the file gives a 404, not the virtual file. A store owner running Rank Math removed their robots.txt and got a 404 from every plugin. The cause was an Nginx config with a location = /robots.txt block and no route to PHP; replacing it with a try_files fallback fixed it. (WordPress.org forum, July 2024)
  • Robots.txt and sitemap both 404 on Nginx. Another site on Nginx got “404 not found” for both files. Support pointed first at the permalink setting, then at the same try_files block for the virtual robots.txt. (WordPress.org forum, June 2020)
  • A broad wildcard blocks the wrong page. A site owner wrote a robots.txt with help from an AI assistant. A Disallow: /*/feed rule meant for feeds also matched a page whose slug started with “feedback”, and Search Console flagged it as indexed though blocked. (WordPress.org forum, August 2026)
  • Expecting the discourage setting to block crawlers. The old forum answer that the setting serves Disallow: / is still quoted, but it changed in WordPress 5.3. Today the setting adds noindex and leaves robots.txt alone. (WordPress.org forum, core change note)
  • Robots.txt behind a firewall challenge. In the Rank Math thread above, the site also ran robots.txt through a Cloudflare geo challenge, and the plugin developer pointed out that crawlers cannot pass it. The owner excluded robots.txt from the rule. (WordPress.org forum, July 2024)

Should every WordPress site have a physical robots.txt?

No. If the default output plus your SEO plugin’s additions does what you need, the virtual file is easier to live with: plugin settings keep working, the sitemap URL stays in sync, and a site migration cannot leave behind a stale copy. Go manual when one of these is true:

  • You need rules your SEO plugin cannot express, and you do not want a mu-plugin.
  • Your server cannot route /robots.txt to WordPress (a subfolder install, or a locked Nginx config you cannot change).
  • You want the file served without PHP at all, which is cheaper on a site that is crawled heavily.
  • You run several apps on one domain and WordPress is only one of them.

On multisite, remember the scope. A crawler reads one robots.txt per host. A subdirectory network shares a single file at the main domain, and core does not add the robots.txt route for a site whose home URL has a path. A subdomain network gets a separate virtual file per subdomain, but one physical file in the shared root would answer for all of them.

If the robots.txt work is part of a broader clean-up of what your site exposes publicly, the sitemap is the next file to look at. Our guide to every way WordPress hands out usernames covers the user sitemap that core lists in wp-sitemap.xml.

FAQ

Where do I put robots.txt in WordPress?

In the folder that serves your domain root, the one containing index.php. Crawlers request https://yoursite.com/robots.txt only, so a file in a subfolder is never read.

Can I delete the robots.txt file in WordPress?

Yes. If you delete a physical file, WordPress goes back to serving its virtual one, as long as permalinks are not Plain and your server routes the URL to PHP. Back it up first and check the live URL afterwards.

Why does my robots.txt show Yoast or Rank Math content I did not add?

Those plugins filter the virtual file. They swap the sitemap line for their own index and may add rules for things like internal search URLs. Change it in the plugin’s settings, or replace it with a physical file if you want full control.

How long does Google take to see a new robots.txt?

Usually within a day, since Google caches the file for up to 24 hours. You can ask for a faster refetch from the robots.txt report in Search Console.

Does robots.txt affect SEO rankings?

Indirectly. It decides what Google can fetch. Blocking CSS, JavaScript or important pages hurts how they are rendered and understood; a clean file that only blocks low-value URLs helps crawlers spend time on pages that matter. It does not remove pages from the index.

Is robots.txt different on WordPress multisite?

Each host gets one file. A subdirectory network shares the main site’s robots.txt; a subdomain network gets a virtual file per subdomain unless a physical file in the shared root overrides them all.

Part of the Wbcom Designs family

The all-in-one WordPress community stack

Also ours: wbcomdesigns.comvapvarun.combrndle.com