,

How to Edit and Optimize the WordPress Robots.txt File for SEO

Optimize WordPress robots.txt for SEO

The robots.txt file is a short text file at the root of your site that tells search engine crawlers which parts of the site they may fetch. WordPress generates a sensible default, and for most blogs the right robots.txt is only a few lines long. The risk runs the other way: one wrong line can block Google from your CSS, your images, or the whole site. This guide explains what the file does, how to edit it in WordPress with Rank Math, Yoast, or by hand, what an optimized file looks like in 2026, and how to test it. It also covers the new question of whether to block AI crawlers.

What Robots.txt Does (and Does Not Do)

When a crawler such as Googlebot arrives, it reads yourdomain.com/robots.txt first and follows its rules about which URLs to crawl. Three things to understand before editing:

  • It controls crawling, not indexing. A page blocked in robots.txt can still appear in Google if other sites link to it; Google just cannot read it. To keep a page out of search results, use a noindex meta tag (Rank Math and Yoast set this per page) and leave it crawlable.
  • It is advisory. Well-behaved bots obey it; scrapers ignore it. It is not a security tool.
  • Blocking resources hurts rankings. Google renders pages like a browser. If robots.txt blocks /wp-content/ or /wp-includes/, Google cannot load your CSS and JavaScript and may judge the page broken or not mobile-friendly.

The Commands

  • User-agent: which crawler the rules apply to. * means all of them.
  • Disallow: a path the crawler should not fetch.
  • Allow: an exception inside a disallowed path.
  • Sitemap: the full URL of your XML sitemap. You can list several.

WordPress’s virtual default looks like this:

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

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

How to Edit Robots.txt in WordPress

With Rank Math

Go to Rank Math > General Settings > Edit robots.txt. Edit the text and save. Rank Math serves the file dynamically, so this works even if no physical file exists. If a physical robots.txt file is present in your root folder, the editor is disabled until you delete that file.

With Yoast SEO

Go to Yoast SEO > Tools > File editor. If no file exists, click Create robots.txt file; otherwise edit and save.

Editing robots.txt in an SEO plugin

By hand

Create a plain text file named robots.txt and upload it to the root of your site (the folder containing wp-config.php, usually public_html) with cPanel File Manager or FileZilla. A physical file overrides the WordPress virtual one.

An Optimized Robots.txt for WordPress in 2026

Less is more. This is what we recommend for a typical blog:

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

Sitemap: https://yourdomain.com/sitemap_index.xml
  • /wp-admin/ keeps crawlers out of the dashboard; admin-ajax.php is allowed because themes and plugins call it on the front end.
  • /?s= and /search/ stop crawlers wasting time on internal search result pages, which are thin and infinite.
  • /go/ (or whatever prefix your affiliate link plugin uses) keeps cloaked affiliate redirects out of the crawl.
  • Sitemap points to the index your SEO plugin generates: /sitemap_index.xml for Rank Math and Yoast, /wp-sitemap.xml for core WordPress. See how to create a sitemap.

What not to add, even though older guides (including the first version of this post) suggested it:

  • Disallow: /wp-content/plugins/ or /wp-includes/: blocks CSS and JavaScript Google needs to render pages.
  • Disallow: /wp-content/uploads/: removes your images from Google Images.
  • Blocking categories, tags, author pages, or feeds: use noindex in your SEO plugin instead if you want them out of search.
  • Disallow: /: deindexes the entire site over time. The one line that must never be there.

Should You Block AI Crawlers?

Since 2023 the AI companies publish crawler names you can block: GPTBot (OpenAI), ClaudeBot (Anthropic), Google-Extended (Google’s AI training, separate from Googlebot), CCBot (Common Crawl), PerplexityBot, and others. Blocking them stops your content being used for model training by bots that honor robots.txt, but it can also remove you from AI answers and search features that now send real traffic. Many publishers block training crawlers and allow search-related ones. If you decide to block, add separate groups:

User-agent: GPTBot
Disallow: /

User-agent: Google-Extended
Disallow: /

Do not block Googlebot, Bingbot, or the AI search crawlers (OAI-SearchBot, Claude-SearchBot) if you want to appear in those search products.

Testing Your Robots.txt

Google removed the old robots.txt Tester. Now open Google Search Console > Settings > Crawling > robots.txt to see the version Google last fetched, any errors, and request a recrawl. To check whether a specific URL is blocked, paste it into the URL Inspection tool; a blocked page shows “Blocked by robots.txt” under crawl. The Bing Webmaster Tools robots.txt tester still works for syntax checks.

Checking robots.txt in Search Console

Frequently Asked Questions

Where is the robots.txt file in WordPress?

At yourdomain.com/robots.txt. If no physical file exists, WordPress generates one on the fly, and SEO plugins let you edit that virtual file from the dashboard.

Does robots.txt improve SEO?

A correct file avoids problems (blocked resources, wasted crawl budget) rather than adding ranking power. For a small blog the main benefit is pointing crawlers to your sitemap and keeping them out of search results pages.

How do I stop Google indexing a page?

Add a noindex tag to that page in Rank Math or Yoast (Advanced tab) and leave it crawlable. Blocking it in robots.txt can keep it in the index as a URL-only listing.

How long does Google take to notice robots.txt changes?

Google refetches robots.txt roughly once a day. You can request a recrawl in Search Console under Settings > robots.txt.

Comments

15 responses to “How to Edit and Optimize the WordPress Robots.txt File for SEO”

Leave a Reply

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

  1. Kirstov Avatar
    Kirstov

    Istiak good summary, maybe you can try our free plugin if interested

    https://wordpress.org/plugins/virtual-robotstxt-littlebizzy/

    that can work on Nginx or Apache servers too.

  2. John Avatar
    John

    seem to be this function is removed on new wordpress seo plugin.
    is there other way to edit it on admin page?

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      It’s still there. Check again.

  3. Daveak Carter Avatar
    Daveak Carter

    Thanks for the article. I used bits and pieces and so far it seems to be working rather well. I didn’t know much about robots.txt before this, but finally got a working one that registers in Google’s console, again thank you. I had to leave out disallowing /wp-includes/ as this seemed to break the site in Google’s console.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Glad I could help.

  4. Pramod Kumar Avatar
    Pramod Kumar

    Thanks, but there is no need to block any Wp directory because if you blocked /Wp-content/plugins/ or /Wp-includes/ then search engines will not crawl your pages properly. So it’s good. Should not block these two folders.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Thanks for the suggestions. Blocking /wp-content/plugins/ is not a problem as this folder only contains plugins. But blocking /wp-includes/ can be a little bit risky as it may block some scripts from bots. So yes, it’s a good idea not to disallow the /wp-includes/ folder.

  5. Masud Parvage Avatar
    Masud Parvage

    Hello brother Istiak,
    I got confused about robots.txt file. I know it is very important for crawling the site. Could you tell me- is the creating procedure system is same for any other CMS or any programming language like PHP? However thanks for sharing the knowledge. It will clear the importance of having a robots.txt file.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Yes, it’s same. Just create a robots.txt file on your computer and upload it to your root directory.

  6. Riju Debnath Avatar
    Riju Debnath

    Hi Istiyak
    I have already done the setup of Yoast SEO with the help of your previous post. Now from this post I am going to copy your ideal model of robots.txt file into my site. Thanks for such a detailed guide on robots.txt. All my confusions are gone now.

    1. Istiak Rayhan Avatar
      Istiak Rayhan

      Glad I could help.

  7. Vikash Sharma Avatar
    Vikash Sharma
    <