Affiliate Notes a working handbook

43 notes5 topics

Robots.txt in WordPress: a six-step setup for bloggers

How WordPress robots.txt works, what to change, and how to handle AI crawlers and affiliate /go/ links, using Google's official rules. A six-step setup.

Topic: SEO and Traffic11 min read Added

In this note

TL;DR

WordPress already serves a basic robots.txt file, even if you never create one. On most blogs, the only changes worth making are listing your sitemap, choosing which AI crawlers to allow, and blocking any on-site affiliate redirect folder. Robots.txt controls crawling, not indexing, so it can’t keep a page out of Google by itself.

Difficulty: Beginner

Time to first result: Google usually refreshes its copy of the file within about a day. Effects you can actually see in Search Console take longer, so check back over the following weeks.

Robots.txt is a plain text file at the root of your domain (yoursite.com/robots.txt). It tells crawlers, the bots that fetch pages for search engines and AI companies, which URLs they may request. Two terms matter throughout. Crawling is a bot downloading a page. Indexing is a search engine storing that page so it can show it in results. Robots.txt only affects crawling, and most robots.txt mistakes come from treating it as an indexing tool.

What WordPress does before you touch anything

If your site’s root folder has no physical robots.txt file, WordPress creates a virtual one whenever a bot asks for it. According to the WordPress core reference for do_robots(), the default output is:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
  • User-agent: * applies the rules to every crawler.
  • Disallow: /wp-admin/ keeps bots out of the dashboard area.
  • Allow: /wp-admin/admin-ajax.php makes an exception for that one file inside the blocked folder.

Since WordPress 5.5, core has also generated an XML sitemap index at /wp-sitemap.xml, and the virtual robots.txt points to it. An XML sitemap is a machine-readable list of the URLs you want search engines to find. If you’ve ticked “Discourage search engines from indexing this site” under Settings > Reading, those core sitemaps are switched off.

Older guides say that checkbox adds Disallow: / to robots.txt. It hasn’t done that since WordPress 5.3. Core now adds a robots meta tag to the page HTML instead. So if your site is missing from Google, check that Reading setting before you go looking for a robots.txt block.

Once you upload a real robots.txt file to the root folder, it replaces the virtual one completely. Anything WordPress added automatically, including the sitemap line, is gone unless you write it in yourself.

Crawling vs indexing: why robots.txt can’t hide pages

Google’s introduction to robots.txt says a blocked URL can still be indexed if other sites link to it. It can appear in results with no description, because Google was never allowed to read the page.

To keep a page out of search results, use one of these instead:

  • a noindex robots meta tag or HTTP header
  • password protection
  • deleting the page

Google also warns that crawl rules and index rules can cancel each other out. If robots.txt blocks a page, Google can’t crawl it, so it never sees the noindex tag on that page.

The framework

1. Look at what your site serves right now

Open yoursite.com/robots.txt in a browser. You’ll see one of three things:

  • The WordPress default: the three lines above, plus a sitemap line on 5.5 and later. This means you have no physical file, which is fine.
  • A plugin-generated file: this one includes your SEO plugin’s sitemap, such as sitemap_index.xml.
  • A custom physical file: this may have been left by a theme, a previous developer or an old tutorial. Read every line, because rules copied from old guides cause most of the trouble.

You can’t safely edit the file until you know which system is producing it. Editing the plugin version while a physical file overrides it changes nothing.

2. Give every rule a job

Before you add a line, write down what it’s for. On a typical blog, these are legitimate jobs:

  • pointing crawlers to your sitemap
  • keeping bots out of admin areas (WordPress already does this)
  • stopping Google from fetching on-site redirect URLs, such as an affiliate /go/ folder
  • opting out of specific AI crawlers

Many blog guides also tell you to block /wp-includes/, plugin folders, feeds or internal search URLs. Google’s rules page doesn’t recommend any WordPress-specific paths. If you can’t name the job a rule does, leave it out. A short file is easier to debug.

3. Choose how you’ll edit it

Through an SEO plugin. In Yoast SEO, go to Yoast SEO > Tools > File Editor and click “Create robots.txt file.” Yoast’s starter file has User-agent: *, an empty Disallow: (which allows everything) and a link to Yoast’s sitemap. The File Editor only shows up if file editing is enabled in WordPress. If editing is disabled, or WordPress can’t write the file, you’ll need FTP or your host’s tools.

In Rank Math, go to Rank Math SEO > General Settings > Edit robots.txt. Its default rules already include your sitemap. Rank Math mentions an advanced editor for PRO users.

Through FTP or your host’s file manager. Create a plain text file named robots.txt and upload it to the top-level directory of your domain. A copy in a subfolder won’t be read.

Through code. Developers can change the virtual file with the robots_txt filter, which has been available since WordPress 3.0. Most bloggers don’t need this.

4. Write rules using Google’s actual syntax

Google’s robots.txt specification is short. These are the points that catch people out:

  1. Google supports only four fields: user-agent, allow, disallow and sitemap. It ignores crawl-delay and everything else.
  2. Paths are case-sensitive, but field names aren’t. Disallow: /Go/ doesn’t block /go/.
  3. * matches any run of characters, and $ marks the end of a URL. For example, Disallow: /*.pdf$ blocks URLs that end in .pdf.
  4. When an allow rule and a disallow rule both match, Google follows the one with the longer path. If they tie, it follows the less restrictive one. This is why WordPress’s Allow: /wp-admin/admin-ajax.php beats Disallow: /wp-admin/.
  5. You can list more than one sitemap. Put each on its own Sitemap: line, as a full URL.
  6. The size limit is 500 KiB, and Google ignores anything past it.
  7. The file only applies to the exact protocol, host and port it’s served from, so shop.yoursite.com needs its own file.

5. Decide what to do about AI crawlers

Each AI company uses separate tokens for training and for search, so blocking the wrong one can cost you visibility you wanted to keep.

  • Google-Extended is a token, not a separate crawler. It controls whether your content is used to train Gemini and for grounding in Gemini Apps and Vertex AI. Google says it doesn’t affect inclusion in Google Search and isn’t a ranking signal.
  • OpenAI has three agents, according to its crawler documentation. GPTBot collects training data. OAI-SearchBot powers ChatGPT search, and if you block it your site won’t appear in ChatGPT search answers, though it may still show as a navigation link. OpenAI says changes take about 24 hours to apply. ChatGPT-User fetches pages when a person asks for them, and OpenAI says robots.txt rules may not apply to it.
  • Anthropic uses ClaudeBot for training, Claude-SearchBot for search indexing and Claude-User for fetches a user asks for. You block each one separately. Anthropic says blocking the search and user agents may reduce your visibility, and that you need rules on every subdomain.

If your affiliate site depends on being found, a reasonable middle ground is to block the training tokens and allow the search ones. Whether that trade suits you depends on your goals. No setting here guarantees traffic from any AI product.

6. Test, then monitor

Google usually caches robots.txt for up to 24 hours, so a fix doesn’t take effect the moment you save it. To see what Google fetched, open the robots.txt report in Search Console under Settings. It only works for Domain properties, covers your top 20 hosts and shows:

  • the fetch status (Fetched, Not Fetched (404), or Not Fetched for another reason)
  • when Google last checked the file
  • the file size
  • any parsing errors or warnings

After an urgent fix, use “Request a recrawl.” Google doesn’t promise to recrawl newly unblocked URLs straight away. The old standalone robots.txt Tester was retired in November 2023, as Search Engine Roundtable reported, so any tutorial that sends you there is out of date.

Know how Google treats a file it can’t fetch. A 4xx error (other than 429) counts as having no robots.txt, which means no restrictions. A 5xx server error is more serious. Google stops crawling for the first 12 hours, then uses the last good copy for up to 30 days. If your host has frequent outages, that’s a reason to fix the hosting.

Example walkthrough: a coffee gear affiliate blog

Say you run example.com, a blog that reviews home espresso grinders and kettles. It uses core WordPress sitemaps. A link plugin sends affiliate clicks through example.com/go/product-name, and there’s a staging copy at staging.example.com. You want to stay visible in Google and in AI search tools, but you don’t want your content used for AI training.

  1. Check the current file. The site serves the WordPress default with the core sitemap line, and there’s no physical file.
  2. Give each rule a job. The jobs are: keep the admin default, stop Google fetching /go/ redirects, opt out of the training crawlers, and list the sitemap.
  3. Choose the editor. The SEO plugin has a file editor, so you use that.
  4. Write the file:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /go/

User-agent: GPTBot
Disallow: /

User-agent: ClaudeBot
Disallow: /

User-agent: Google-Extended
Disallow: /

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

OAI-SearchBot and Claude-SearchBot aren’t blocked, so the site can still appear in those search products. This is now a real file, so you have to write the sitemap line by hand. If your SEO plugin generates its own sitemap, use that URL instead of the core one.

  1. Handle staging separately. A robots.txt on staging.example.com would only cover that host, and it still wouldn’t reliably keep the copy out of Google. Password-protect staging instead.
  2. Test. Open the robots.txt report and confirm the status is Fetched with no parsing errors. Then check again the next day.

If you’re still setting up the site itself, how to start a blog and make money online covers the steps before this one, and WordPress vs Wix vs Squarespace for affiliate sites explains why WordPress gives you this level of file control.

The /go/ line has an official basis. Google’s page on qualifying outbound links says that if you don’t want Google to fetch a link to a page on your own site, you should use a robots.txt disallow rule. An on-site redirect folder is that kind of page.

That rule only controls crawling. The same Google page says ads and paid placements should be marked rel="sponsored", with rel="nofollow" as a fallback when other values don’t apply. Google’s page doesn’t mention affiliate links by name. A commission link is still a financial relationship, so our cautious reading is to mark those links sponsored as well as disallowing /go/. The robots.txt rule doesn’t replace the link attribute.

The FTC expects you to disclose any financial, employment, personal or family relationship with a brand in a way people can’t miss. Its guide is written for social media and says a disclosure only in a profile or bio isn’t enough. Our reading is that a note only in your blog’s footer or About page has the same problem, so put a clear disclosure near the affiliate links themselves. This is general information, not legal advice. If you’re unsure, ask a qualified professional.

Common mistakes

  • Using robots.txt to hide thin or private pages. This stops Google from reading a noindex tag, and the URL can still be indexed through outside links. Use noindex and let Google crawl the page.
  • Uploading a physical file and losing the sitemap line. The real file replaces the virtual one completely, so add the Sitemap: line yourself.
  • Copying long rule lists from old tutorials. If you block paths without knowing what they do, you can create crawling problems that are hard to trace later.
  • Adding Crawl-delay for Google. Google ignores it. Anthropic supports it, so it only matters for crawlers that honor it.
  • Blocking AI search bots when you only meant to block training. GPTBot and OAI-SearchBot are separate decisions, and so are ClaudeBot and Claude-SearchBot.
  • Case mismatches. /Recommends/ and /recommends/ are different paths.
  • Expecting a file to fix traffic. A clean robots.txt only removes friction. On a new site, rankings and affiliate income take months of publishing and promotion. The six-step free traffic framework covers that side, and WordPress blog pagination covers another crawl setting that’s often misconfigured.

Tools (free first)

  • Your browser. Visiting /robots.txt is the fastest check.
  • Google Search Console (free). The robots.txt report is the official way to confirm what Google fetched and whether it parsed without errors.
  • Your host’s file manager or an FTP client (usually free). Use this when your plugin’s editor doesn’t appear.
  • SEO plugins. Yoast and Rank Math both have robots.txt editors and generate sitemaps. Neither help page clearly says whether the editor is free, so check inside your own install before you upgrade. A premium SEO plugin can be worth paying for because of its other features, but not just to edit a text file you can manage over FTP.

Recap

  • WordPress serves a virtual robots.txt by default, and a physical file in the root replaces it entirely.
  • Robots.txt controls crawling, not indexing. Use noindex or password protection to keep pages out of search.
  • Only add rules that have a clear job: your sitemap, the admin area, on-site redirect folders and your AI crawler choices.
  • Pair a /go/ disallow with rel="sponsored" on affiliate links and a clear FTC disclosure.
  • Confirm every change in Search Console’s robots.txt report, and allow about a day for Google to refresh its copy.

Next, learn how noindex and canonical tags work, because they handle the indexing decisions robots.txt can’t.

Sources are linked inline. Fees and rules change, so confirm anything important on the platform’s own pages. How these notes are researched