Guides

WordPress robots.txt: What It Does and How to Set It Up Safely

Bilal Haider 5 min read

WordPress robots.txt: What It Does and How to Set It Up Safely

A robots.txt file is a small text file that tells search engine crawlers which parts of your site they may crawl. It is easy to get wrong, and a single bad line can keep search engines away from your whole site. It is also widely misunderstood: it is not a way to hide pages from Google.

This guide explains what robots.txt does in WordPress, what a safe file looks like, how to edit it, and how to check that it works.

What robots.txt does, and what it does not do

Google explains that robots.txt is mainly used to manage crawler traffic to your site. It is not a mechanism for keeping a web page out of Google. To keep a page out of search results, use a noindex rule or password protection. A URL blocked by robots.txt can still appear in search results without a description (Google Search Central). Also, not every crawler obeys robots.txt.

Where the file lives

The file must be named robots.txt, saved in UTF-8, and placed at the root of your site, for example https://yoursite.com/robots.txt. A copy in a subfolder does not work, and each host (including each subdomain) needs its own file (Create a robots.txt file). You can see yours by opening that address in a browser.

What WordPress gives you by default

If there is no physical robots.txt file, WordPress generates one on the fly. According to WordPress’s developer reference, the default output tells all crawlers to stay out of /wp-admin/ while still allowing /wp-admin/admin-ajax.php, and the result can be changed with the robots_txt filter (do_robots()). This is the file currently served by this website:

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

That is a safe, minimal file. It keeps crawlers out of the admin area, keeps the AJAX endpoint available (many themes and plugins use it), and points to the sitemap.

What each line means

LineMeaning
User-agent: *The rules below apply to all crawlers
Disallow: /wp-admin/Do not crawl the admin area
Allow: /wp-admin/admin-ajax.phpMake an exception for the AJAX file
Sitemap: ...The full address of your sitemap (optional, and it can appear more than once)

Rules are case-sensitive, and the Sitemap line must use a fully qualified address.

How to edit robots.txt in WordPress

Step 1: Look at what you have now

Open yoursite.com/robots.txt and copy the current text somewhere safe.

Step 2: Decide what, if anything, to change

Most small business sites need no changes. Add rules only for a clear reason, such as blocking crawl-heavy internal search result pages or a staging folder. You can draft a file with my robots.txt generator for WordPress.

Step 3: Create or edit the file

You have two common options. You can upload a physical robots.txt file to the site root with SFTP or your hosting file manager, which takes priority over the virtual one. Or you can use the file editor in your SEO plugin, if it has one. Save the file as plain UTF-8 text and take a copy of the old version first.

Step 4: Check it

Reload yoursite.com/robots.txt and confirm your new text. Google refreshes its cached copy about every 24 hours. To make it re-read the file sooner, use Request a recrawl in the Search Console robots.txt report (Google: update robots.txt).

The “Discourage search engines” setting

WordPress has a visibility option in Settings > Reading. Since WordPress 5.3, discouraging search engines no longer adds Disallow: / to robots.txt and relies on the robots meta tag instead, according to WordPress’s changelog for the robots function. Turn it on while building a site, and make sure it is switched off when you launch.

Common mistakes

  • Leaving Disallow: / in place after launch. This tells crawlers to stay away from the whole site. Check this first if your pages are not showing up.
  • Trying to hide private pages with robots.txt. The file is public, and blocked URLs can still appear in results. Use noindex or password protection.
  • Blocking a page you want to noindex. If crawlers cannot fetch the page, they cannot see its noindex tag.
  • Blocking pages that carry structured data. Google’s guidelines say not to block such pages with robots.txt.
  • Wrong case or location. Rules are case-sensitive, and the file must be at the site root.

Troubleshooting

  • Your changes do not show: a physical file, a plugin, or a cache may be serving an older version. Clear the cache and check which file is being served.
  • Search Console says a page is blocked by robots.txt: find the rule that matches that URL and remove or narrow it.
  • A page you blocked still appears in Google: that is possible. Use noindex or password protection instead, and let crawlers fetch the page so they can see the noindex.
  • Nothing at /robots.txt: a security plugin or server rule may be blocking it. Check with your host.

Frequently asked questions

Do I need a robots.txt file?

Not necessarily. WordPress generates a sensible default if none exists. You need a custom one only when you have a specific reason to control crawling.

Should I put my sitemap in robots.txt?

It is allowed and common. The Sitemap line is optional and needs the full address.

Does robots.txt stop hackers or scrapers?

No. It is a request to well-behaved crawlers, not a security tool. For protection, follow the WordPress security checklist.

Next steps

If you also want search engines to understand your pages better, read how to add schema markup to WordPress. For help with technical SEO on your site, see my services or request a free website audit.

Written by Bilal Haider, WordPress designer and developer. Last updated: November 23, 2026.

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep reading

Related articles

Start your project

Let's build a website that wins you clients

Tell me about your business and goals. Within 24 hours you get a clear plan, a fixed-price quote and honest advice, with no pressure and no obligation.