How to add ads.txt to WordPress without a plugin (and avoid conflicts with virtual ads.txt files)
Key takeaways
- On a self-hosted WordPress site, a physical ads.txt file uploaded to the web root is served directly by Apache or Nginx, before WordPress runs.
- WordPress's basic .htaccess rules only send a request to index.php when it does not match an existing file or directory (RewriteCond %{REQUEST_FILENAME} !-f and !-d).
- WordPress's recommended Nginx configuration uses try_files $uri $uri/ /index.php?$args, which also serves an existing static file before PHP.
- Because a physical file wins, a plugin that generates a virtual ads.txt through WordPress is ignored when a real ads.txt file exists in the web root.
- If WordPress lives in its own subdirectory but the site is served at the domain root, ads.txt goes in the public root next to the copied index.php, not in the WordPress folder.

To add ads.txt to a self-hosted WordPress site without a plugin, create a plain text file named ads.txt with your AdSense line and upload it via SFTP or your host’s file manager to the web root, the folder that serves https://yourdomain.com/. Apache and Nginx serve that file directly, before WordPress loads, which also means it overrides any plugin-generated virtual ads.txt.
Why use a file instead of a plugin?
Google’s Ads.txt FAQs suggest a plugin as one option for WordPress (“If you already use a plugin to place ads, it might include a feature to create your ads.txt file”). A plugin is not required. A physical file has practical advantages:
| Physical file in web root | Plugin (virtual file) | |
|---|---|---|
| Served by | Web server, before PHP | WordPress, through PHP |
| Depends on plugin updates | No | Yes |
| Affected by PHP errors or maintenance mode | No | Can be |
| Affected by page caching plugins | Not usually (static file) | Possibly |
| Editing | SFTP or file manager | WordPress dashboard |
| Survives theme changes | Yes | Yes |
The main reason to prefer a plugin is access: if you cannot reach your files, a plugin with an editor in the dashboard is easier.
How do I add ads.txt to WordPress, step by step?
- Copy your line from AdSense. In “Sites”, open the site, select the “Ads.txt snippet” option and click “Copy”. It looks like
google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0(see ads.txt syntax). - Create the file in a plain text editor. Google’s Ads.txt guide suggests Notepad (Windows) or TextEdit (Mac). In TextEdit, switch to plain text before saving. Name it exactly
ads.txt. - Add other networks, one line each, from their own documentation.
- Connect to your server with SFTP or your host’s file manager.
- Find the web root: usually the folder that contains
wp-config.php,wp-admin,wp-contentandwp-includes, often namedpublic_html,wwworhtdocson shared hosting. - Upload
ads.txtthere. - Open
https://yourdomain.com/ads.txtin a private window. You should see plain text. - In AdSense, click “Check for updates” on the site’s page. Google says changes may take a few days, up to a month for sites with few ad requests.
Why does a real file win over WordPress?
Because WordPress only handles requests the web server cannot satisfy itself.
Apache. The basic WordPress .htaccess block, as published in Apache HTTPD / .htaccess, ends with:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
In mod_rewrite, -f tests whether the path “exists, and is a regular file”, -d whether it is a directory, and a ! prefix makes the condition true “only if the CondPattern does not match”. So the rule sends a request to index.php only when no real file or directory matches. A real /ads.txt is served as a static file.
Nginx. WordPress’s Nginx configuration uses:
try_files $uri $uri/ /index.php?$args;
The page’s own comment: “no php is touched for static content.” Nginx serves the existing file first and falls back to index.php only when nothing matches.
What is a “virtual” ads.txt, and why does it conflict?
Unlike robots.txt, which WordPress core can output itself through do_robots(), ads.txt comes either from a physical file or from a plugin. Some plugins write a real file to disk; others answer the /ads.txt request from inside WordPress, with the content stored in the database and printed by PHP. That second kind is a “virtual” ads.txt: there is no file to find on the server.
Combine that with the routing above and the conflict is predictable:
| Situation | What visitors and crawlers get |
|---|---|
| Physical file only | The physical file |
| Plugin only | The plugin’s virtual output |
| Physical file and plugin | The physical file; the plugin’s settings have no effect |
| Two plugins both managing ads.txt | Depends on load order; hard to predict after updates |
| Neither, with a theme that returns a 404 page | The theme’s HTML 404 page, which AdSense reports as “Not found” |
The classic support ticket: someone edits ads.txt in a plugin, sees the change in the plugin screen, but /ads.txt still shows the old content. A forgotten physical file from an earlier setup is taking precedence. Pick one source of truth. If you follow this guide, disable the ads.txt feature in any ad or SEO plugin that offers one.
What about special WordPress setups?
WordPress in its own directory
With Giving WordPress Its Own Directory, core files live in a subfolder such as /wordpress while the site is served at the root, and you “Copy (NOT MOVE!) the index.php and .htaccess files” to the root. In that case ads.txt goes in the public root next to the copied index.php, not inside /wordpress. The test is always the URL: https://yourdomain.com/ads.txt must return it.
Multisite
On a subdirectory network (example.com/site2/), all sites share one domain and therefore one ads.txt at the root. On a subdomain network (site2.example.com), the root domain’s file covers every subsite unless it declares subdomain= entries, as explained in ads.txt and subdomains. Mapped custom domains each need their own file at their own root, which a physical file in a shared web root cannot provide per domain; that is one of the few cases where a plugin or server-level rule is the practical answer.
Managed hosts and CDNs
Some managed WordPress hosts put a CDN or full-page cache in front of the site. If you change the file and still see the old version, purge the cache for /ads.txt in the host’s dashboard. If your host blocks file uploads to the web root, ask them to place the file; Google’s FAQ advises contacting your provider when a CMS “doesn’t let me place a file on my root domain.”
How do I confirm which source is answering?
When you suspect a plugin and a file are competing, test it instead of guessing:
- Look for the file on disk. In the file manager or SFTP client, check whether
ads.txtexists in the web root. If it does not, whatever/ads.txtreturns comes from WordPress or a plugin. - Compare the content. Open the file on disk and
https://yourdomain.com/ads.txtside by side. Different content means a cache or another source is in the way. - Rename the file temporarily to
ads.txt.bakand reload/ads.txtin a private window. If the URL still returns ads.txt lines, a plugin is generating them; if it returns your theme’s 404 page, the physical file was the only source. Rename it back right away. - Check the response with curl:
curl -sI https://yourdomain.com/ads.txt
You want status 200 and a content-type of text/plain. Keep the test short so crawlers do not catch the file missing.
File permissions matter too. The web server must be able to read the file; on typical Linux hosting, 644 (owner can write, everyone can read) is the usual setting for a static file. A file uploaded with restrictive permissions can return 403.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
/ads.txt shows a themed 404 page |
File not in the web root, or wrong name (ads.txt.txt, Ads.txt) |
Upload to the folder that serves /, check the exact name |
/ads.txt shows old content |
Physical file overriding a plugin, or cache | Remove one source, purge the cache |
| Browser downloads the file instead of showing it | Server sends an unusual Content-Type | Check curl -sI; the spec requires text/plain |
Works on www, AdSense says “Not found” |
Bare domain does not redirect | Redirect example.com/ads.txt to the www URL |
| Strange characters at the start of the file | Saved with a byte order mark or as rich text | Re-save as plain text without BOM |
| Security plugin returns 403 | Firewall rule on .txt files |
Allow /ads.txt |
For anything beyond these, the full delivery checklist (HTTPS, redirects, robots.txt) is in ads.txt Not found or Unauthorized. To add the AdSense code itself without a plugin, see AdSense on WordPress without a plugin.
Frequently asked questions
Where exactly do I upload ads.txt on a WordPress site?
In the directory that answers requests for your domain root, usually the folder that contains wp-config.php, wp-admin and wp-content (often called public_html or www on shared hosting). If WordPress is installed in a subdirectory but the site is served at the root, use the root folder that holds the copied index.php instead.
Do I need a plugin for ads.txt on WordPress?
No. Google's Ads.txt FAQs suggest considering a plugin, but a plain text file uploaded to the web root works on any self-hosted WordPress site and does not depend on PHP, plugin updates or caching layers. A plugin is convenient when you cannot access files via SFTP or the hosting file manager.
I have a real ads.txt and a plugin that manages ads.txt. Which one is served?
The real file, on standard Apache and Nginx setups. WordPress's .htaccess rules and recommended Nginx try_files line serve an existing file before handing the request to WordPress, so the plugin's virtual output never runs. Edits made in the plugin's settings then have no visible effect. Keep only one source: delete the file or disable the plugin's ads.txt feature.
Can I edit ads.txt from the WordPress dashboard without a plugin?
Not with core WordPress features. Use your host's file manager or an SFTP client to create and edit the file. Avoid editing it through a word processor or rich-text field: Google advises a plain text editor because rich text can add formatting characters that make the file hard to parse.
Sources
- Ads.txt FAQs · Google AdSense Help
- Ads.txt guide · Google AdSense Help
- Apache HTTPD / .htaccess · WordPress Developer Resources
- Nginx · WordPress Developer Resources
- Giving WordPress Its Own Directory · WordPress Developer Resources
- Apache Module mod_rewrite · Apache HTTP Server Project
Related guides
- How to add AdSense to WordPress without a plugin (classic and block themes)
Add AdSense to WordPress without a plugin: the wp_head hook, in-content units via the_content, block theme template parts, and ads.txt in the web root.
- ads.txt "Not found" or "Unauthorized": a technical checklist for redirects, HTTPS, status codes and robots.txt
Diagnose ads.txt Not found and Unauthorized statuses: root vs www, HTTP vs HTTPS, redirect rules, 404 and soft 404, robots.txt, content type, with curl tests.
- ads.txt syntax for AdSense, line by line: pub ID, DIRECT, TAG ID, comments and variables
The AdSense ads.txt line field by field: google.com, your pub ID, DIRECT, f08c47fec0942fa0, plus comments, variables and the formatting errors that break parsing.
- How to fix the AdSense "Earnings at risk" ads.txt alert
Why AdSense shows the Earnings at risk ads.txt alert, what Not found and Unauthorized really cost you, and how to fix it and get the warning cleared faster.