How To Add An Ads.txt File In WordPress For Ad Revenue Compliance

You Just Set Up Your WordPress Site for Ads, But Something Is Missing

You’ve installed your ad management plugin, configured your ad slots, and maybe even signed up with Google AdSense or another ad network. The dashboard looks good, and you’re ready to start earning. Then, you get an email or see a warning in your ad network’s dashboard: “No ads.txt file found.” Your potential revenue could be at risk because of a simple text file.

This isn’t a complex coding challenge or a server configuration nightmare. It’s a straightforward, yet critical, piece of housekeeping for any website monetizing with display advertising. If you’re seeing that warning, you’re in the right place. Let’s fix it.

What Is an Ads.txt File and Why Is It Non-Negotiable?

Think of an ads.txt file as a public directory for your website’s advertising inventory. It stands for Authorized Digital Sellers. Created by the Interactive Advertising Bureau (IAB), its sole purpose is to combat ad fraud, specifically domain spoofing.

Here’s the problem it solves: a bad actor could claim to be selling ad space on your popular website “example.com” to an advertiser, but then serve the ad on a low-quality, unrelated site. The advertiser pays for your audience but doesn’t get it. The ads.txt file acts as a public record, listing every company (like Google, Mediavine, or Ezoic) that is officially authorized to sell your ad space.

For you, the publisher, the consequences of not having one are direct. Major ad networks and demand-side platforms (DSPs) will limit or block bids on your inventory. This means lower competition for your ad space, which translates directly to lower fill rates and lower revenue per impression. In short, you’re leaving money on the table. It’s a five-minute task that protects your site’s integrity and your income.

What You’ll Find Inside a Typical Ads.txt File

The file is just plain text with a specific format. Each line represents an authorization. A basic entry for Google AdSense looks like this:

google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0

Let’s break down those four fields, separated by commas:

– The first field is the advertising system’s domain (e.g., google.com).
– The second field is your publisher ID from that system.
– The third field is the relationship type, usually either DIRECT or RESELLER.
– The fourth field is an optional certification authority ID, often provided by the ad network.

Your file will have one line for each ad network you work with. Some managed ad services, like Ezoic or Mediavine, will provide you with a full, pre-written ads.txt content to use.

The Core Solution: Adding Your Ads.txt File to WordPress

You have three main paths to get this file live on your site. The best method depends on your comfort level and how your site is hosted.

Method 1: Using a Dedicated Plugin (The Easiest Way)

This is the recommended method for most WordPress users. It handles file creation, placement, and updates without you touching code or file managers.

First, install and activate a plugin. A reliable, simple option is “Ads.txt Manager” by WP Beginner. You can find it by going to your WordPress admin dashboard, navigating to Plugins > Add New, and searching for “ads.txt”.

Once activated, you’ll find a new “Ads.txt” menu item, often under Settings or Tools. Click into it. The plugin interface is typically a simple text area. Here, you paste the exact ads.txt content provided by your ad networks.

how to add ads.txt file in wordpress

If you use Google AdSense, you can find your specific line by logging into your AdSense account, going to “Sites” under the “Settings” gear icon, and finding the “Ads.txt” section. It will display your unique publisher ID line. Copy that entire line.

Paste all necessary lines into the plugin’s text area and click “Save Changes”. The plugin automatically creates the physical ads.txt file in the correct root directory of your website. You can verify it’s working by visiting yourdomain.com/ads.txt in a new browser tab.

Method 2: Manual Upload via FTP or File Manager (The Direct Way)

If you prefer not to add another plugin or need more control, you can create and upload the file yourself. This method is universal and works on any hosting environment.

Start by creating the file on your computer. Open a simple text editor like Notepad (Windows) or TextEdit (Mac, ensure it’s in plain text mode). Do not use a word processor like Microsoft Word, as it can add hidden formatting.

Type or paste your ads.txt content into this new file. For a site using only Google AdSense, the entire file content would be that single line mentioned earlier.

Now, save the file. This is a critical step: you must name it exactly “ads.txt”. Ensure there is no extra extension like .txt.txt. The file should be plain ASCII/UTF-8 text.

Next, you need to upload this file to the root directory of your WordPress installation. This is the same folder that contains your wp-config.php, wp-content, and wp-admin folders.

– Using FTP: Connect to your site with an FTP client like FileZilla. Navigate to the root directory (often called public_html, www, or your domain name). Drag and drop your local ads.txt file into this remote folder.
– Using cPanel File Manager: Log into your hosting control panel (cPanel). Open the File Manager tool, navigate to the public_html directory, click the “Upload” button, and select your ads.txt file.

Once uploaded, immediately test by going to yourdomain.com/ads.txt. You should see the plain text content you created.

Method 3: Using Code in Your Theme’s Functions.php (The Developer’s Method)

This approach programmatically ensures the file is always available. It’s slightly more advanced but keeps everything within your theme’s code. A word of caution: if you switch themes, this code will stop working.

Access your theme’s functions.php file. You can do this via Appearance > Theme File Editor in your WordPress admin, but editing via a child theme or FTP is safer to prevent loss during theme updates.

Add the following code snippet to the end of your functions.php file:

function myprefix_serve_ads_txt() {
    if ( $_SERVER[‘REQUEST_URI’] === ‘/ads.txt’ ) {
        header( ‘Content-Type: text/plain’ );
        $ads_txt_content = “google.com, pub-0000000000000000, DIRECT, f08c47fec0942fa0\n”;
        // Add more lines for other networks
        echo $ads_txt_content;
        exit;
    }
}
add_action( ‘init’, ‘myprefix_serve_ads_txt’ );

how to add ads.txt file in wordpress

You must replace the example line with your actual ads.txt content. To add multiple networks, add more lines to the $ads_txt_content variable, using the “\n” to create a new line. For example:

$ads_txt_content = “google.com, pub-123456789, DIRECT, f08c47fec0942fa0\n”;
$ads_txt_content .= “example-ssp.com, 12345, DIRECT\n”;
$ads_txt_content .= “anothernetwork.com, abcdef, RESELLER”;

Save the file. This code intercepts requests for /ads.txt and serves the content directly from PHP, bypassing the need for a physical file on the server.

Troubleshooting Common Ads.txt Issues

Even after adding the file, things can go wrong. Here are the most common hiccups and how to solve them.

The File Is Not Accessible or Returns a 404 Error

You uploaded the file, but visiting yourdomain.com/ads.txt shows a “Page Not Found” error. This usually means the file is not in the true document root.

– Check the location: Double-check you placed it in the website’s primary root directory. For a site where WordPress is installed in a subdirectory (e.g., yourdomain.com/blog/), the ads.txt file must be in the main domain’s root, not the WordPress subdirectory.
– Permissions: The file permissions might be incorrect. Using your FTP client or file manager, set the permissions (chmod) for ads.txt to 644. This allows the web server to read it.
– Caching: If you use a caching plugin (like W3 Total Cache, WP Rocket) or a CDN (like Cloudflare), clear all caches. These systems might be serving an old version of your site map that doesn’t include the new file.

Ad Network Still Reports “Not Found” or “Invalid”

Your file is live, but the warning persists in your ad dashboard. This is often a timing or validation issue.

– Crawler delay: Ad network crawlers don’t check your site in real-time. It can take 24-48 hours for them to re-crawl your site and update their status. Be patient for a day or two.
– Syntax error: A single typo, extra space, or missing comma will invalidate the entire line. Go to your live ads.txt URL and copy the entire content. Paste it into a simple ads.txt validator tool (search online for “ads.txt validator”) to check for formatting errors.
– Incorrect ID: The most common mistake is using an old or incorrect publisher ID. Log back into your ad network’s portal and verify you copied the exact, current ID string they provide. Do not use an example ID from a blog post.

Managing Multiple Ads.txt Entries and Conflicts

As you grow, you might work with header bidding wrappers, multiple SSPs, and direct sold campaigns. Your ads.txt file can become long. The key is organization.

– Group related entries: Place all entries for one parent company (like all Google lines) together.
– Use comments: You can add notes in the file by starting a line with a hash (#). For example: “# Entries for Direct Sold Campaigns”. This helps you manage it later.
– Plugin updates: If you use a plugin, it may only manage its own entries. If you also have manual entries in a physical file, you can create a conflict. Standard practice is to let one system manage it entirely—either use only the plugin’s interface or only a manually uploaded file.

Your Action Plan for a Compliant, Revenue-Optimized Site

Adding an ads.txt file isn’t a one-time set-and-forget task. It’s part of your site’s monetization maintenance. Here is your straightforward action plan to implement today and manage going forward.

First, choose your method right now. For 95% of users, installing the “Ads.txt Manager” plugin is the fastest, most reliable path. Do it, paste in your credentials, and save. Then, verify by visiting your site’s /ads.txt URL.

Second, schedule a quarterly check. Every three months, log into your primary ad network dashboards. Check for any notifications about your ads.txt file. When you add a new ad partner, they will provide a new line—add it to your file immediately. This ensures new revenue streams aren’t blocked from the start.

Finally, understand that this file is a sign of a professional, trustworthy publishing operation. It tells advertisers and automated systems that you take your inventory seriously and are committed to a clean, fraud-free ecosystem. That reputation, though invisible to your readers, is foundational to maximizing your ad revenue over the long term. The few minutes you spend today directly secure the earnings from all the traffic you work so hard to attract.

Leave a Comment

close