in

How to Create and Manage Ads.txt files in WordPress?

How to Create and Manage Ads.txt files in WordPress?

Without a doubt, every website owner has a motive to earn some extra money with the site. The primary and the easiest method of monetizing the site is by displaying advertisements. Some of the people believe that mere displaying ad and managing them is sufficient. However, the ads.txt file goes unnoticed by some of the users which causes problems to the users.

This file protects the ad publishers from potential ad fraud and helps them gain trust. As this file maintains transparency with the advertisers, it will help you in getting more ads and result in better ad revenue.

This file is publically available which means that every advertiser can look at the file and know whether your site is genuine and safe to advertise or not. If you have not created the ads.txt file earlier, then here we present you with the complete method on how you can create this file on WordPress.

Method 1 – The Plugin Method

Step 1

The first thing that you need to do is install and activate the Ads.txt Manager plugin. All you have to do is log in to your WordPress admin dashboard, and head over to the Plugins> Add New page. Here look out for the plugin and hit the Install Now corresponding to it. Once the installation is complete, you need to click on the activation link to start using the plugin.

Step 2

Once the plugin is successfully installed, you need to head back to the admin area and navigate to the Settings> Ads.txt page. In this page, you have to paste the lines to declare your resellers. You can add all your resellers in your ads.txt file. Once you are done with that, make sure that you click on the Save Changes button to keep the changes in the file.

This was the complete method of creating the ads.txt file using the Ads.txt Manager plugin. There is another method of doing the same method which is explained below.

Fixing Earnings at Risk Error

Sometimes your Google Adsense account might show the error that your earnings are at risk. It also mentions that your ads.txt file does not contain an AdSense publisher ID. To fix this error, all you have to do is head over to the WordPress admin dashboard and open the Settings> Ads.txt page. Here you need to paste the correct ID and save the changes.

Though this method will create the ads.txt file, but this plugin only words for root domains. This plugin will not work with subdomain and a single site in a multi-site network. If you want to create the ads.txt file in any of these networks, then you can use the manual method.

Method 2 – The Manual Method

Step 1

As its name describes, this is the manual method where you need to paste a certain code into the core WordPress files. To access these files, you need to access the WordPress core directory with the help of your FTP client. The first thing you need to do is connect with your FTP client and open the WordPress directory. Here you can see different files and folders, but you need to open the wp-content folder.

Step 2

In this folder, you need to head over to the Themes> Your Current Theme Folder and download the functions.php file to your system. Once the download completes, you need to paste the following code into the file and save all the changes.

// 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 );

Step 3

Once you have pasted the code into the file, you have to upload the file to the same folder using the FTP client. After creating the file, you can validate it with your reseller.

Why Should You Use the Ads.txt File?

The primary reason for creating this file is to maintain transparency with the advertiser. The biggest fear of every advertiser is dealing with a fraud website which shows fake statistics to get the advertising. When you create the ads.txt file, you are showing all the advertisers that you are currently working with. This list of advertisers helps the new one in gaining trust on your site and creates an authenticity.

Another reason to use this file is that most of the advertising platforms made it compulsory to have it. Almost every advertising platform wants to avoid frauds for their clients which is why they male it necessary to create this file. Whether it is Google AdSense or Ad Exchange, it is mandatory to have an ads.txt file on your website.

Endnote

There is no harm in creating an ads.txt file for your website. Instead, it will only provide you with the benefits. You can use any of the methods mentioned above, but you need to keep in mind their process. If you are comfortable with the website coding, then you can opt for the manual method.

Leave a Reply

Your email address will not be published. Required fields are marked *

How to Detect AdBlock Users in WordPress?

How to Detect AdBlock Users in WordPress?

How to Add "Click to Load" for GIFs in WordPress?

How to Add “Click to Load” for GIFs in WordPress?