Independent, hands-on guides to hosting, SEO and marketing tools. No paid rankings, ever.See how we test →

WordPress Robots.txt: How to Edit It and What to Include

Learn how WordPress robots.txt works, what to include, what to avoid, and how to edit it safely without blocking key pages.

Serp & Server is reader-supported. When you buy through links on our site, we may earn an affiliate commission, at no extra cost to you. It never decides our rankings. Here’s how it works.

WordPress robots.txt guide shown as crawler paths and gates
Jump to a section

WordPress robots.txt is a small but important file that tells search engine crawlers which parts of your site they may fetch.

For most business websites, it should be simple: keep important pages crawlable, avoid blocking design files, and point crawlers towards your sitemap. This guide explains how the WordPress robots.txt file works, when to change it, and what a sensible version should include.

What WordPress robots.txt does

A robots.txt file is a public text file at the root of a site, such as https://example.com/robots.txt. Search engines check it before crawling, then decide which URLs they are allowed to request.

The WordPress robots.txt file is mainly about crawl control, not privacy. Google warns that robots.txt should not be used to hide sensitive pages, because a blocked URL can still be discovered from links elsewhere and some crawlers may ignore the rules.

Use it to reduce crawler access to unhelpful areas, not to protect passwords, customer details, invoices, staging sites, or private documents. Those need proper access control, such as passwords, authentication, or server-level restrictions.

Find your WordPress robots.txt file

Open your browser and add /robots.txt to your domain name. If your site is on https://www.example.co.uk, visit https://www.example.co.uk/robots.txt.

Most WordPress robots.txt output is virtual, meaning WordPress generates it when the URL is requested. You may not see an actual file in your hosting file manager unless you or a plugin has created one.

WordPress core exposes a default sitemap index at /wp-sitemap.xml on modern installations, and its sitemap component can add that sitemap reference to robots.txt. You can read the official WordPress sitemap note on the Make WordPress Core site.

Check the right version of the site

Robots.txt applies per protocol and host. That means https://example.com/robots.txt, https://www.example.com/robots.txt, and https://shop.example.com/robots.txt can all be different.

Google’s Search Console help explains that robots.txt must sit at the root of the relevant host and protocol. If your site uses both www and non-www versions, check the live version that visitors and search engines actually use.

When to edit robots.txt WordPress

You only need to change robots.txt when there is a clear crawling reason. For example, you may want to keep crawlers away from internal search results, duplicate filter URLs, or low-value generated pages.

WordPress robots.txt rules shown as crawl paths and sitemap directions
Robots.txt guides crawlers, but it does not secure private content.

Before you edit robots.txt WordPress rules, ask whether you really mean “do not crawl” or “do not show in search”. If you want a page kept out of Google results, a noindex tag or password protection is usually the better tool.

  • Use robots.txt for crawl control on unimportant or repetitive URL patterns.
  • Use noindex for pages that can be crawled but should not appear in search results.
  • Use passwords or private permissions for anything confidential.
  • Use redirects when an old URL has permanently moved.

If your hosting is slow or unreliable, fixing that is better than trying to block half the site from crawlers. Our WordPress hosting guides explain the hosting basics that affect crawlability and site speed.

What to include in WordPress robots.txt

A sensible robots.txt for a normal WordPress site is short. It should avoid blocking public content, CSS, JavaScript, images, and other files that search engines need to render pages properly.

This is a safe starting point for many brochure sites, blogs, and small business websites:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/wp-sitemap.xml

For many small sites, this WordPress robots.txt example is enough. Replace the sitemap URL with your own domain and your actual sitemap path if an SEO plugin uses a different sitemap, such as /sitemap_index.xml.

Common rules and what they mean

RuleWhat it doesUse it?
User-agent: *Applies the following rules to all crawlers that respect robots.txt.Yes, for general rules.
Disallow: /wp-admin/Asks crawlers not to fetch the WordPress admin area.Yes, usually.
Allow: /wp-admin/admin-ajax.phpAllows a WordPress AJAX endpoint that some public features may use.Yes, if blocking /wp-admin/.
Sitemap:Points crawlers to your XML sitemap or sitemap index.Yes, if the sitemap is valid.
Disallow: /wp-content/Blocks themes, uploads, scripts, and other public assets.No, avoid this.

Google’s robots.txt introduction says the file is mainly for managing crawler traffic, and that important resources should not be blocked if Google needs them to understand a page. Its sitemap documentation also confirms that you can declare a sitemap in robots.txt using a Sitemap: line.

How to edit your file safely

Use these routes to change WordPress robots.txt only when you know what needs to change. Take a copy of the current output first, so you can roll back quickly if a rule blocks something important.

Edit robots.txt WordPress with a plugin

This is the safest route for many site owners. SEO plugins often include a robots.txt editor, although the exact menu location changes between plugins and versions.

After saving, open /robots.txt in a private browser window and confirm the live output. Do not assume the plugin screen and the public file are identical until you check.

Edit via a physical file

You can create a real robots.txt file in the public root of your hosting account, often called public_html, www, or the site folder. On most setups, a physical file overrides the virtual WordPress robots.txt output.

This method is useful if you want server-level control or if WordPress is not loading correctly. The downside is that WordPress and SEO plugins may no longer add sitemap changes automatically.

Edit with a small code snippet

Developers can use the WordPress robots_txt filter to adjust the generated output. The official WordPress developer reference documents this hook.

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

This keeps the WordPress robots.txt output dynamic, but code changes should go in a small site plugin or a carefully managed child theme. Avoid pasting snippets from random forums without understanding what each line blocks.

Rules to avoid

Do not use WordPress robots.txt as a dumping ground for every folder you recognise. Blocking core folders can stop search engines from fetching scripts, styles, images, and files needed to assess your pages properly.

  • Do not block /wp-content/uploads/ unless you deliberately want media files excluded from crawling.
  • Do not block /wp-content/themes/ or /wp-content/plugins/ just because they look technical.
  • Do not block CSS or JavaScript required for layout, menus, forms, or product pages.
  • Do not block a page and add noindex to the same page, because crawlers may never see the noindex.
  • Do not list secret-looking folders, because robots.txt is public.

Be careful with AI crawler rules too. Some crawlers respect robots.txt and some do not, user-agent names can change, and blocking AI bots may have side effects if you copy broad rules without checking them.

Testing your WordPress robots.txt

After saving, open your WordPress robots.txt URL in a browser and check that it returns a clean text file. If you see a theme template, a 404 page, or a caching error, fix that before worrying about the rules themselves.

Then test key URLs in Google Search Console. The robots.txt report and URL Inspection tool can help you spot whether important pages are blocked.

  1. Check the live /robots.txt URL.
  2. Confirm your sitemap URL opens and contains valid URLs.
  3. Inspect your homepage, a service page, a blog post, and an image URL.
  4. Look for accidental blocks in Search Console.
  5. Clear site, plugin, CDN, and host caches after edits.

If you unblock important URLs, Google says you can request a robots.txt recrawl in Search Console, although this does not guarantee immediate recrawling of those pages. In most cases, Google will revisit the file automatically.

WordPress Robots.txt FAQs

What is the best WordPress robots.txt file for a small business site?

A simple WordPress robots.txt file usually works best: block /wp-admin/, allow /wp-admin/admin-ajax.php, and include your sitemap URL. Avoid blocking public pages, images, CSS, JavaScript, themes, or plugin assets unless you have a specific technical reason.

Can robots.txt stop a page appearing in Google?

Not reliably. Robots.txt can stop Google from crawling a URL, but the URL may still appear if Google discovers it through links elsewhere. If you want a page excluded from search results, use noindex or password protection instead.

Why can I see robots.txt in the browser but not in my hosting files?

WordPress can generate robots.txt dynamically, so there may be no physical file in your file manager. If you create a real robots.txt file in the site root, it will usually take over from the generated version.

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

Usually, no. The wp-content folder contains uploads, themes, scripts, and styles that search engines may need to understand your pages. Blocking it can make your site harder to crawl and render correctly.

How often should I check my robots.txt?

Check it after a redesign, migration, SEO plugin change, staging-to-live launch, or hosting move. Otherwise, reviewing it a few times a year is enough for most small WordPress sites.

Final word

A clean WordPress robots.txt setup is usually short, boring, and effective. Let search engines crawl your public pages, keep the admin area out of bounds, and include the right sitemap.

The biggest mistake is trying to solve indexing, privacy, speed, and SEO problems with one tiny text file. Use robots.txt for crawl guidance, and use the right WordPress setting, plugin option, redirect, password, or hosting fix for everything else.

Enjoyed this guide?

Get the newsletter

Get more guides like this one on the topics you choose. Confirm your email and you are done.

  • Pick only the topics you care about
  • About one email a week, no spam
  • Change topics or unsubscribe any time
Newsletter signup


Serp & Server Avatar

Written by

Keep reading