WordPress robots.txt guide showing crawl rules, Allow and Disallow directives, sitemap.xml and the website root directory

How to Create a robots.txt File for WordPress

By Hridoy Ahmed · Updated October 26, 2026 · 7-minute read

To create a robots.txt file for WordPress, choose the rules you actually need, add the correct XML sitemap URL, and make the file available at your domain root: https://yourdomain.com/robots.txt. WordPress can serve a virtual robots.txt automatically, so you may not need to upload a physical file. Before changing anything, check the current file and avoid rules that accidentally block important pages or resources.

Want to create your file now? Use the generator below, then follow the steps in this guide to check and publish the result.

If the embedded generator does not load in your browser, open the free Robots.txt Generator on its own page.

What does robots.txt do in WordPress?

A robots.txt file gives compatible crawlers instructions about which URL paths they should or should not request. It is mainly a crawl-management file, not a security feature and not a reliable way to remove URLs from search results. Google can still index a URL it discovers elsewhere even when crawling is disallowed. To keep a page out of Google, use an appropriate noindex directive while allowing Google to crawl the page, or protect private content with authentication. Google’s robots.txt documentation explains this distinction.

Before you create a new file, check the one you already have

Open https://yourdomain.com/robots.txt in your browser, replacing the example domain with your own. WordPress can generate a virtual robots.txt when there is no physical file in the site root. If a physical file already exists, it generally takes precedence over WordPress’s virtual output and may also override rules added dynamically by plugins. Do not overwrite it until you understand what its current rules do.

If you use Rank Math or another SEO plugin, check its robots.txt editor and sitemap settings first. You may only need to adjust the existing rules rather than create a separate file.

Create a robots.txt file in WordPress: step by step

1. Choose an appropriate preset

Use the generator to start with a WordPress-friendly preset. “Allow all” is appropriate only if you intentionally want no custom crawl restrictions. A “block all” preset can prevent crawlers from accessing the entire site and must not be used on a live website that should appear in search.

2. Add your actual sitemap URL

Add a Sitemap: line only for a sitemap that really exists on your site. Rank Math commonly uses /sitemap_index.xml; WordPress core also has a sitemap endpoint at /wp-sitemap.xml. These are examples, not interchangeable assumptions—open your sitemap in a browser and add the correct URL for your setup.

3. Add only necessary crawl rules

For many standard WordPress sites, keeping the admin area out of ordinary crawling is enough. Avoid broad rules that block the whole site, media, CSS, JavaScript, or important content. Be especially careful with wildcard rules: a small syntax change can affect many URLs.

4. Generate and review the file

Use the generator to create the text, then read every Allow and Disallow line before publishing. Make sure the example domain in any sitemap line has been replaced with your real sitemap URL. A generator can help with syntax, but it cannot know your entire site architecture or business requirements automatically.

5. Publish it at the site root

You can use your hosting file manager or SFTP to upload a file named exactly robots.txt to your website’s document root—the same level where your main WordPress installation is served. If you manage rules through an SEO plugin, use its editor instead and avoid maintaining conflicting versions in multiple places.

6. Verify the live result

Open https://yourdomain.com/robots.txt again and confirm that the version served publicly matches the rules you intended. Check that the sitemap URL opens successfully. Then review important URLs in Google Search Console, especially if you have recently changed crawl rules or noticed indexing problems.

Example: a simple WordPress robots.txt

This is an illustrative starting point, not a file to copy blindly. Replace the example sitemap with the one that actually works on your site, and keep rules suited to your own setup.

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

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

The example leaves public content available for crawling while excluding the admin path from ordinary crawler requests and allowing the AJAX endpoint. If your SEO plugin already outputs different rules or a sitemap line, compare them before replacing anything.

What should you block—and what should you leave crawlable?

  • Consider restricting: low-value URL spaces that create unnecessary crawling, but only after checking the effect on your site.
  • Do not casually block: article pages, important landing pages, images, CSS, JavaScript, or files needed to understand how a page renders.
  • Do not use robots.txt for privacy: the file is public, and compliant crawlers may still discover a blocked URL from links.
  • Do not use robots.txt as a noindex substitute: a blocked page may not be crawled, so Google may not see its noindex directive.

Common robots.txt mistakes in WordPress

  • Blocking the whole site: a broad Disallow: / rule can stop compliant crawlers from crawling the site. Never publish it accidentally.
  • Blocking a page you want removed from Google: use a suitable noindex method or access protection instead of relying on robots.txt.
  • Blocking resources used to render pages: do not block CSS or JavaScript without a clear technical reason.
  • Using the wrong sitemap URL: test the sitemap first; do not assume every WordPress setup uses the same path.
  • Editing the wrong file: confirm that you changed the file at the correct domain root and that a host or plugin is not serving a different version.
  • Maintaining conflicting rule sets: decide whether the physical file or the plugin/virtual configuration is the source of truth.

How to check whether your robots.txt change worked

  1. Visit the live /robots.txt URL and inspect the response.
  2. Test the sitemap URL in a browser and confirm that it returns a valid sitemap.
  3. Check a few important pages in Google Search Console’s URL Inspection tool to confirm Google can access them.
  4. Review crawl or indexing reports for unexpected changes after publishing the file.

Changes do not guarantee an immediate ranking or indexing improvement. The goal is to give crawlers accurate instructions and avoid unintentionally blocking pages that should be found.

Frequently asked questions

Does WordPress create robots.txt automatically?

WordPress can serve a virtual robots.txt file when there is no physical file in the site root. Plugins may filter or add to that output. Check the live URL before creating or uploading another version.

Where should I upload robots.txt?

Place it in the document root for the relevant domain so it loads at https://yourdomain.com/robots.txt, not in a subfolder such as /wp-content/.

Will robots.txt remove a page from Google?

No. Robots.txt primarily controls crawling. Use a supported noindex directive for pages that should not appear in search, and make sure crawlers can access the page to read that directive.

Should I block AI crawlers?

That is a separate business and publishing decision. Different crawlers may have different purposes and may not all follow the same rules. Review the purpose of each crawler before adding a block. Read the related guide to AI crawlers and robots.txt.

Do I need a custom robots.txt if Rank Math is active?

Not necessarily. If the current rules are correct, there may be no need to create a physical file. Check your SEO plugin settings, the live robots.txt and your sitemap before making changes.

About the author: Hridoy Ahmed is an SEO specialist and WordPress security expert based in Dhaka, Bangladesh, helping website owners with technical SEO, WordPress optimization and website security.

Need a quick starting point? Open the free WordPress robots.txt generator and review the generated file before you publish it.

Leave a Comment

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