Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
No Result
View All Result

How to Set Up and Manage the Ads.txt For WordPress

January 23, 2018
in Tutorials
0 0
Share on FacebookShare on Twitter

Have you heard of the new ads.txt standard? In this article, we will be going over what ads.txt is and why it is necessary. We will answer the question, what ads.txt means and how you can create and manage ads.txt for your WordPress website.

In the last couple of years, instances of Ad fraud has tripled. To help prevent this the Interactive Advertising Bureau – IAB‎, the governing body responsible for advertisements on the internet, together with top ad companies have developed an approach called Ads.txt which is very similar to the Robots.txt used by web crawlers. Ads.txt protects publishers from ad fraud, and it can potentially increase your ad revenue.

What is Ads.txt File?

Ads.txt is a text file that allows publishers to declare who can sell ads on their website. It is an initiative created by IAB Tech Lab, a non-profit focused on improving digital advertising standards.

The initiative is supported by Google’s advertising platforms like Google Adsense, Doubleclick, and Ad Exchange. It is also supported by many other leading digital advertising platforms.

The primary goal of the ads.txt project is to increase transparency in the programmatic advertising ecosystem. Ads.txt stands for Authorized Digital Sellers and is a simple, flexible and secure method that publishers and distributors can use to publicly declare the companies they authorize to sell their digital inventory.

According to the IAB tech lab, by creating a public record of Authorized Digital Sellers, ads.txt will create greater transparency in the inventory supply chain, and give publishers control over their inventory in the market, making it harder for bad actors to profit from selling counterfeit inventory across the ecosystem.

As publishers adopt ads.txt, buyers will be able to more easily identify the Authorized Digital Sellers for a participating publisher, allowing brands to have confidence they are buying authentic publisher inventory.

Why is Ads.txt file important?

Ad fraud cost millions of dollars in damages to online advertisers and publishers each year. People with malicious intent continuously try to trick ad platforms with domain spoofing, fake clicks, fake impressions, and more.

Ads.txt file improves transparency in the online advertisement by allowing publishers to declare who can sell their ad inventory. Here is how it works:

If you are an advertiser and someone tells you that they can display your ad on a particular website, then you can go and checkout that website’s ads.txt file. It will show you if the company you are dealing with has the permission to sell advertising space on that particular website or not.

Since this data is publicly available, it can be crawled, stored, and searched by advertisers, publishers, and resellers.

If you are displaying ads on your website using Google Adsense, DoubleClick, or Ad Exchange, then adding Ads.txt file is recommended. Many other advertising platform and software also support or require ads.txt file to be declared.

We will be going over 2 different ways to set up ads.txt on your website. As a side note, the ads.txt file is supposed to be in the root directory of your website.

1. How to Set Up Ads.txt Files in Using a Plugin

The first approach we are going to see is to use a plugin. WordPress makes it easy to install plugins and extend the functionality of your website.
To set this up, you need to install and activate the Ads.txt Manager plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Once you have successfully activated the plugin, you need to visit the Settings » Ads.txt page to configure plugin settings.

You can then add your publisher details in the text box provided. One thing to note is that this plugin currently only works for root level domain like example.com. It does not work for WordPress installed in a subdomain, subdirectory, or a single site in a multi-site network.

2. How to Set Up Ads.txt with a code change

This second approach will look at adding some code changes to functions.php which will allow you to enable ads.txt. Paste the code below into the functions.php to allow you to setup your ads.txt.

// TODO: change `my_theme` prefix to my theme's prefix!
/**
 * Register the rewrite rule for /ads.txt request.
 */
function my_theme_adstxt_rewrite() {
    add_rewrite_rule( '^ads\.txt$', 'index.php?my_theme_adstxt=true', 'top' );
}
add_action( 'init', 'my_theme_adstxt_rewrite', 10 );
 
/**
 * Filter the list of public query vars in order to allow the WP::parse_request
 * to register the query variable.
 *
 * @param array $public_query_vars The array of whitelisted query variables.
 *
 * @return array
 */
function my_theme_adstxt_query_var( $public_query_vars ) {
    $public_query_vars[] = 'my_theme_adstxt';
    return $public_query_vars;
}
add_filter( 'query_vars', 'my_theme_adstxt_query_var', 10, 1 );
 
/**
 * Hook the parse_request action and serve the ads.txt when custom query variable is set to 'true'.
 *
 * @param WP $wp Current WordPress environment instance
 */
function my_theme_adstxt_request( $wp ) {
    if ( isset( $wp->query_vars['my_theme_adstxt'] ) && 'true' === $wp->query_vars['my_theme_adstxt'] ) {
        /*
         * Set proper content-type per specification in
         * https://iabtechlab.com/wp-content/uploads/2017/09/IABOpenRTB_Ads.txt_Public_Spec_V1-0-1.pdf :
         *
         * The HTTP Content-type should be ‘text/plain’, and all other Content-types should be treated
         * as an error and the content ignored.
         */
        header( 'Content-Type: text/plain' );
 
        // The code expects an existing ads.txt file in the root of your active theme.
        echo file_get_contents( get_stylesheet_directory() . '/ads.txt' );
        exit;
    }
}
add_action( 'parse_request', 'my_theme_adstxt_request', 10, 1 );

Once you have successfully setup your ads.txt Upon activation, you can validate it with your ad provider.

Troubleshooting Earnings at risk Error in Adsense

A missing declaration in your ads.txt file may result in the following warning message in your Google Adsense account.

Earnings at risk – One or more of your ads.txt files doesn’t contain your AdSense publisher ID. Fix this now to avoid severe impact to your revenue.

This message indicates that your ads.txt file doesn’t have your publisher ID. To fix this message, simply go to Settings » Ads.txt page to make sure that you have correct publisher ID in plugin settings.

We hope this article helped you learn how to create and manage the ads.txt file in WordPress. Feel free to leave your comments on your experience with installing ads.txt.

Tags: ads.txt
ShareTweetPin
Previous Post

How to Properly Force Logout for All Users in WordPress

Next Post

How to Make Private Posts and Pages in WordPress

Next Post

How to Make Private Posts and Pages in WordPress

You might also like

Mint Linux vs Ubuntu: Which is Right For You?

Mint Linux vs Ubuntu: Which is Right For You?

March 12, 2022
Net Neutrality: What is it and Why Should You Care?

Net Neutrality: What is it and Why Should You Care?

March 12, 2022
Solid State Drives – Why You Should Buy One Today

Solid State Drives – Why You Should Buy One Today

March 12, 2022

Machine Learning Algorithms Every Beginner Should Know

January 25, 2022
What Is the log4j Vulnerability, log4shell, an Example Step-By-Step Exploit and How to Fixed It

What Is the log4j Vulnerability, log4shell, an Example Step-By-Step Exploit and How to Fixed It

December 11, 2021
Simple Video Call integration into Website with Jitsi

Simple Video Call integration into Website with Jitsi

May 26, 2020
  • Terms of Service
  • Privacy Policy
  • Careers

© 2021 Dotlayer.com

No Result
View All Result
  • About Us
  • Advertise
  • Blog
  • Careers
  • Contact
  • Contact Us
  • Get Featured
  • Home Layout 1
  • Home Layout 2
  • Home Layout 3
  • Privacy Policy
  • Security
  • Services
  • Subscribe To Dotlayer
  • Terms of Service
  • Write For Us

© 2021 Dotlayer.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In