Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
30 Million+
Websites using our plugins
20+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Optimize Your WordPress Robots.txt for SEO

Your WordPress site already has a robots.txt file and it’s making decisions about what search engine crawlers can access, whether you’ve ever touched it or not.

Most of those decisions are harmless. But a single poorly chosen rule can also keep crawlers away from URLs you actually want them to discover.

In this guide, we’ll show you what your robots.txt file is doing right now how to edit it without touching code.

Optimizing a WordPress robots.txt file for SEO

Here is everything we will cover in this guide:

What Is a Robots.txt File?

Robots.txt is a plain text file that tells search engine bots which parts of your site they can crawl.

The file lives in the root directory (the main folder) of your website. The basic format looks like this:

User-agent: [user-agent name]
Disallow: [URL string not to be crawled]

User-agent: [user-agent name]
Allow: [URL string to be crawled]

Sitemap: [URL of your XML Sitemap]

You can add as many rules and sitemaps as you need. If you do not disallow a URL, bots assume they can crawl it.

Your site works fine without a robots.txt file when you first start a blog. However, as your content grows, this file becomes more useful.

Search engines give each website a crawl budget, which is the number of pages they will crawl in a given timeframe. By blocking unimportant pages, you help bots spend that budget on the content you want in search results.

This matters most for large sites with thousands of pages.

Keep in mind that robots.txt helps you control crawling, not indexing.

  • Crawling is when search engine bots (like Googlebot) visit your website to discover its content.
  • Indexing is when they add that content to their massive search database so it can appear in search results.

Think of it like a librarian reading a new book (crawling) and then adding it to the library’s catalog (indexing).

In other words, robots.txt is also not a good way to hide content because a disallowed page can still appear in search results if other websites link to it. To reliably keep a page out of Google, use a ‘noindex’ meta tag instead. This tells search engines not to list the page at all.

Robots.txt Examples and Best Practices

For most WordPress sites, you can keep your robots.txt file fairly simple. Here is the basic setup we recommend:

User-Agent: *
Allow: /wp-content/uploads/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-admin/
Disallow: /readme.html
Disallow: /refer/
Disallow: /?s=

Sitemap: https://www.example.com/post-sitemap.xml
Sitemap: https://www.example.com/page-sitemap.xml

Here is what each rule does:

  • Allow: /wp-content/uploads/ lets search engines crawl your images and other files uploaded to your WordPress media library.
  • Allow: /wp-admin/admin-ajax.php keeps WordPress’s AJAX handler accessible. Themes and plugins may use this file to load or update content without refreshing the page.
  • Disallow: /wp-admin/ prevents crawlers from accessing your WordPress admin area, which doesn’t contain content you want appearing in search results.
  • Disallow: /readme.html prevents crawlers from accessing WordPress’s default readme.html file. This file isn’t useful to search engines, so there is little reason for them to crawl it.
  • Disallow: /refer/ prevents crawlers from following affiliate or other redirect URLs that use the /refer/ prefix. If your site uses a different prefix for these links, replace /refer/ with your own.
  • Disallow: /?s= prevents crawlers from requesting WordPress’s internal search URLs. These pages generally aren’t useful landing pages for search engines and can create many unnecessary URLs to crawl.
  • Sitemap tells search engines where to find your XML sitemaps. This makes it easier for them to discover the URLs you want them to crawl.

These are the same core types of rules we use on WPBeginner. You can see our live file at wpbeginner.com/robots.txt. Our production file contains additional rules for a much larger site, but the basic principles are same.

Keep in mind that using the* wildcard applies to all crawlers.

For example, this rule blocks Googlebot from crawling the /private/ folder:

User-agent: Googlebot
Disallow: /private/

Common user agent names include Googlebot (Google), Bingbot (Bing), and Baiduspider (Baidu).

How to Create a Robots.txt File in WordPress

There are two ways to create a robots.txt file in WordPress. You can choose the method that works best for you.

Method 1: Editing Robots.txt File Using All in One SEO

Most free WordPress SEO plugins, like All in One SEO (AIOSEO), Yoast, or Rank Math, allows you to customize your robots.txt file right from your WordPress dashboard.

We use AIOSEO on WPBeginner. The free version of AIOSEO helps you validate your robots.txt rule as you type, which enables you to catch syntax errors before it goes live. 

Once the plugin is active, simply go to All in One SEO » Tools in your WordPress dashboard. You will land on the Robots.txt Editor. Turn on the ‘Enable Custom Robots.txt’ toggle to start editing.

Enable custom robots.txt toggle

The editor shows the default rules that WordPress generates on its own.

Now you can add your own rules. Enter a user agent in the ‘User Agent’ field, or use * to apply the rule to all bots.

Then choose ‘Allow’ or ‘Disallow’ in the Directive column, and type the file or folder path in the ‘Value’ field. To add another rule, click the ‘Add Rule’ button.

Adding a custom rule in the All in One SEO robots.txt editor

You can check your finalized file in the ‘Custom Robots.txt Preview’ at the bottom of the screen. It shows the full file exactly as bots will see it.

All in One SEO robots.txt preview

When you are done, click the ‘Save Changes’ button to save your rules.

Method 2: Editing Robots.txt File Manually Using FTP

If you’d rather edit your robots.txt file directly, then follow this method. To edit the file, you will need to use an FTP client or the file manager in your WordPress hosting panel.

Before you edit anything, download a backup copy of your current robots.txt file to your computer. That way, you can restore it if something goes wrong.

First, connect your FTP client to your WordPress website and find the robots.txt file in your website’s root folder.

Edit robots file via FTP

If you do not see one, your site does not have a robots.txt file yet. You can create one right there.

Robots.txt is a plain text file. You can download it, edit it in any plain text editor like Notepad or TextEdit, and upload it back to your root folder.

How to Test Your Robots.txt File

After creating or editing your robots.txt file, always check it for errors. A small typo can block important pages from search engines, and you may not notice for weeks.

The easiest way to test your robots.txt file for errors is with Google Search Console.

First, make sure your site is connected to Google Search Console. If it is not, follow our guide on how to add your WordPress site to Google Search Console.

Then go to your Search Console dashboard and open Settings from the bottom-left menu. Find the ‘Crawling’ section and click ‘Open Report’ next to ‘robots.txt’.

Opening the robots.txt report in Google Search Console Settings

Click the current version of the file in the list. The report shows the latest robots.txt that Google has found, and it highlights any syntax errors or logical problems it detected.

Google Search Console robots.txt report showing a valid file

If you just updated your file and the changes are not showing up, give it a day and then check it again. 

Frequently Asked Questions About WordPress Robots.txt

Here are the most common questions readers ask us about optimizing the robots.txt file in WordPress.

1. Can using robots.txt improve my site’s security?

No, robots.txt is not a security measure. The file is publicly visible, so it doesn’t actually block anyone from accessing the URLs you list. It simply provides directives for well-behaved search engine crawlers.

2. Should I block WordPress category and tag pages in robots.txt?

No, you should not block category and tag pages. These archive pages carry internal links that crawlers follow to reach your older posts, so blocking them removes a discovery path for the content you do want indexed.

3. What’s the difference between robots.txt and the noindex tag?

They control different things. Robots.txt controls whether a crawler can visit a URL at all. The noindex tag controls whether search engines list a page in search results, even if they’ve already visited it.

Use robots.txt to block crawlers from areas like your admin panel, staging environment, or plugin directories. Use noindex for pages you’re fine with Google crawling, like filtered archive pages or thank-you pages, that you just don’t want appearing in search results.

We hope this article helped you learn how to optimize your WordPress robots.txt file for SEO. You may also want to see our ultimate WordPress SEO guide and our expert picks for the best WordPress SEO tools to grow your website.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

133 CommentsLeave a Reply

  1. I have to admit, I use the AIOSEO plugin but have always ignored the “Enable Custom Robots.txt” option because I didn’t want to mess anything up.
    But I have read this article and I’m convinced it’s worth taking the time to optimize my site’s robots.txt file.

      • I think you should modify your response. It should be https instead of http. Is it right to disallow plugin files too?

        • Thank you for pointing that out, our sample has been updated. For disallowing plugins you would want to check with the specific plugin to be safe.

  2. Thanks for this informative post about robots.txt file.
    I didn’t know that websites should maintain this file in order to have a control over Google bots that how should they crawl over our pages and posts.
    for beginner websites just starting out, is there a need to have robots.txt file or is there a way like plugin which can a make a robots.txt file for our website?

    • Most SEO plugins help with setting up the robots.txt for a new site to prevent bots from scrolling sections they shouuldn’t.

      Admin

  3. Thanks to this article, I checked the robots.txt file and added URL addresses with sitemaps. At the same time, I had other problematic lines there, which were revealed by the validator. I wasn’t familiar with sitemaps in robots.txt until now. Thanks.

  4. Hi,

    Thanks for that post, it becomes clearer how to use the robots.txt file. On most websites that you find while looking for some advice regarding the robots.txt file, you can see that the following folders are explicitly excluded from crawling (for WordPress):
    Disallow: /wp-content/plugins
    Disallow: /wp-content/cache
    Disallow: /wp-content/themes

    I don’t really understand the reasons to exclude those folders (is there one actually?). What would be your take regarding that matter?

    • It is mainly to prevent anything in those folders from showing as a result when a user searches for your site. As that is not your content it is not something most people would want to appear for the site’s results.

      Admin

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

    GSC show the coverage error for “Disallow: /wp-admin/” Is this wrong?

    • For most sites, you do not want anything from your wp-admin to appear as a search result so it is fine and expected to receive the coverage area when you deny Google the ability to scan your wp-admin.

      Admin

  6. I am creating my robots.txt manually as you instructed for my WordPress site.

    I have one doubt. when I write User-Agent: * won’t it allow another spamming robot to access my site?
    Should I write User-Agent: * or User-Agent: Googlebot.?

    • The User-Agent line is setting the rules that all robots should follow on your site, if you specify a specific bot on that line it would be setting rules for that specific bot and none of the others.

      Admin

  7. should we also disallow /wp-content/themes/ ?

    It is appearing in the search result when I run the command site:abcdef.com in google search

    • You would not want to worry about blocking your themes folder and as you write SEO-friendly content you should no longer see the themes as a search result.

      Admin

    • That means you’re telling search engines to not look at any referral links or the readme.html file.

      Admin

    • If you block your uploads folder then search engines would not normally crawl your uploaded content like images.

      Admin

  8. Sir i m very confused about robot.txt many time i submitted site map in blogger but the after 3,4 days coming the same issue what is the exactly robot.txt.. & how submit that please guide me

  9. Hi
    I have a question
    i receive google search console coverage issue warning for blocked by robots.txt
    /wp-admin/widgets.php
    My question is, can i allow for wp-admin/widgets.php to robots.txt and this is safe?

  10. Hello! I really like this article and as I’m a beginner with all this crawling stuff I would like to ask something in this regard. Recently, Google has crawled and indexed one of my websites on a really terrible way, showing the pages in search results which are deleted from the website. The website didn’t have discouraged search engine from indexing in the settings of WordPress at the beginning, but it did later after Google showed even 3 more pages in the search results (those pages also doesn’t exist) and I really don’t understand how it could happen with “discourage search engine from indexing” option on. So, can the Yoast method be helpful and make a solution for my website to Google index my website on the appropriate way this time? Thanks in advance!

    • The Yoast plugin should be able to assist in ensuring the pages you have are indexed properly, there is a chance before you discouraged search engines from crawling your site your page was cached.

      Admin

      • Well yes and from all pages, it cached the once who doesn’t exist anymore. Anyway, as the current page is on “discourage” setting on, is it better to keep it like that for now or to uncheck the box and leave the Google to crawl and index it again with Yoast help? Thanks! With your articles, everything became easier!

        • You would want to have Google recrawl your site once it is set up how you want.

  11. Hi I loved the article, very precise and perfect.
    Just a small suggestion kindly update the image ROBOTS.txt tester, as Google Console is changed and it would be awesome if you add the link to check the robots.txt from Google.

    • Thank you for the feedback, we’ll be sure to look into updating the article as soon as we are able.

      Admin

  12. My blog’s robots.txt file was:
    User-Agent: *
    crawl-delay: 10

    After reading this post, I have changed it into your recommended robots.txt file. Is that okay that I removed crawl-delay

    • It should be fine, crawl-delay tells search engines to slow down how quickly to crawl your site.

      Admin

  13. Thank you for sharing. This was really helpful for me to understand robots.txt
    I have updated my robots.txt to the ideal one you suggested. i will wait for the results now

  14. thanks for update information for me. Your article was good for Robot txt. file. It gave me a piece of new information. thanks and keep me updating with new ideas.

    • For a multisite, you would need to have a robots.txt file in the root folder of each site.

      Admin

  15. My wordpress site is new and my robot.txt by default is
    user-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php

    I want google to crawl and index my content. Is that robot.txt okay?

  16. Great Airticle…

    I was confused from so many days about Robots.txt file and Disallow links. Have copied the tags for robots file. Hope this will solve the issue of my Site

  17. The files in the screenshots of your home folder are actually located under the public_html folder under my home folder.

    I did not have a /refer folder under my public_html folder.

    I did not have post or page xml files anywhere on my WP account.

    I did include an entry in the robots.txt file I created to disallow crawling my sandbox site. I’m not sure that’s necessary since I’ve already selected the option in WP telling crawlers not to crawl my sandbox site, but I don’t think it will hurt to have the entry.

    • Some hosts do rename public_html to home which is why you see it there. You would want to ensure Yoast is active for the XML files to be available. The method in this article is an additional precaution to help with preventing crawling your site :)

      Admin

  18. User-agent: *
    Disallow: /wp-admin/
    Allow: /wp-admin/admin-ajax.php <– This is my robot.txt code but im confuse why my /wp-admin is index? How to no index it?

    • If it was indexed previously you may need to give time for the search engine’s cache to clear

      Admin

  19. This website really inspire me to start a blog .Thank you lost of tema.this website each and every article have rich of information and explanation.when i have some problem at first i visit this blog . Thank You

  20. I am trying to optimise robots for my website using Yoast. However Tools in Yoast does not have the option for ‘File Editor’.
    There are just two options
    (i) Import and Export
    (ii) Bulk editor
    May you please advise how this can be addressed. Could it be that I am on a free edition of Yoast?

    • The free version of Yoast still has the option, your installation may be disallowing file editing in which case you would likely need to use the FTP method.

      Admin

  21. I really find this article helpful because I really don’t know much on how robot.txt works but now I do.

    pls what I don’t understand is how do I find the best format of robot.txt to use on my site (I mean one that works generally)?

    I noticed lots of big blogs I check ranking high on search engine uses different robot.txt format..

    I’ll be clad to see a reply from you or just anyone that can help

    • Having a sitemap and allowing the areas that need to be allowed is the most important part. The disallow part will vary based on each site. We shared a sample in our blog post, and that should be good for most WordPress sites.

      Admin

    • Hey Emmanuel,

      Please see the section regarding the ideal robots.txt file. It depends on your own requirements. Most bloggers exclude WordPress admin and plugin folders from the crawl.

      Admin

  22. Well written article, I recommend the users to do sitemap before creating and enabling their ROBOTS text it will help your site to crawl faster and indexed easily.

    Jack

  23. I keep getting the error message below on google webmaster. I am basically stuck. A few things that were not clear to me on this tutorial is where do I find my site’s root files, how do you determine if you already have a “robots.txt” and how do you edit it?

    • Hi Cherisa,

      Your site’s root folder is the one that contains folders like wp-admin, wp-includes, wp-content, etc. It also contains files like wp-config.php, wp-cron.php, wp-blogheader.php, etc.

      If you cannot see a robots.txt file in this folder, then you don’t have one. You can go a head and create a new one.

      Admin

      • Thank you for your response. I have looked everywhere and can’t seem to locate these root files as you describe. Is there a path directory I can take that leads to this folder. Like it is under Settings, etc?

  24. I had a decent web traffic to my website. Suddenly dropped to zero in the month of May. Till now I have been facing the issue. Please help me to recover my website.

  25. Hello There Thank you For This Information, But I Have A Question
    That I Just Create The Sitemap.xml and Robots.txt File, & Its Crawling well. But How Can I Create “Product-Sitemap.xml”
    There is all list of product in sitemap.xml file. Do I Have To Create Product-sitemap.xml separately?

    and submit to google or bing again ?
    Can You please Help me out…
    Thank You

  26. I have a problem on robots.txt file setting. Only one robots.txt is showing for all websites. Please help me to show separate robots.txt file of all websites. I have all separate robots.txt file of all individual website. But only one robots.txt file is showing in browser for all websites.

  27. Please explain why did you include
    Disallow: /refer/
    in the beginner Robots.txt example? I do not understand the implications of this line. Is this important for the beginner? You have explained the other two Disallowed ones.

    Thanks.

  28. How can I put all tags/mydomain.Com in nofollow? In robots.txt to concentrate the link Juice? Thanks.

  29. hey,,i am getting error in yoast seo regarding site map..once i click on fix it ,,,it’s coming again..my site html is not loading properly

  30. I’ve just been reviewing my Google Webmaster Tools account and using the Search Console, I’ve found the following:
    Page partially loaded
    Not all page resources could be loaded. This can affect how Google sees and understands your page. Fix availability problems for any resources that can affect how Google understands your page.

    This is because all CSS stylesheets associated with Plugins are disallowed by the default robots.txt.

    I understand good reasons why I shouldn’t just make this allowable, but what would be an alternative as I would suspect the Google algorithms are marking down the site for not seeing these.

  31. Hi,

    Whenever, I search my site on the google this text appears below the link: “A description for this result is not available because of this site’s robots.txt”

    How, can i solve this issue?

    Regards

    • Hi Suren,

      Seems like someone accidentally changed your site’s privacy settings. Go to Settings » Reading page and scroll down to ‘Search engine visibility’ section. Make sure that the box next to is unchecked.

      Admin

  32. Hello

    As i seen in webmaster tool, i got robot.txt file like below :

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

    let me know is that okey ? or should i use any other ?

  33. I want to know, does it a good idea to block (disallow) “/wp-content/plugins/” in robots.tx? Every time i remove a plugin it shows 404 error in some pages of that plugin.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.