How to Add an Easy Affiliate Disclaimer to Your WordPress Site

How to Add an Easy Affiliate Disclaimer to Your Wordpress Site

Today, most bloggers are trying to make money from their blogs, and affiliate links are a great way to do this. Affiliate links are when you link to a product on your blog or website, and when your readers click through and buy that product, you receive a small percentage or commission on the sale. If you have enough traffic this is a great way to earn money.

How to Add an Easy Affiliate Disclaimer to Your WordPress Site

But, there’s a small catch. It is illegal to include affiliate links in your posts without disclosing it to your readers. These legalities are understandable, because readers deserve to know that you aren’t just promoting the product because you think it’s great, but also because you are receiving a payout for it. Now in cases like mine, I still only promote products that I think are great, but it’s still necessary to disclose it to your readers.

So, how do you disclose it? The rules explain that you need to have a disclaimer, and you need to include it before the affiliate links themselves. This causes a problem because if you put text at the beginning of your text in WordPress, it automatically would be included in the post preview and the excerpt, and we don’t want the affiliate disclaimer included in that.

The second issue is that if you use a lot of affiliate links, you don’t want to have to manually copy and paste and insert it into every post. So, how do we make it easy to add an affiliate link, before the content, in a place that won’t be in the way of your content?

Enter, advanced custom fields. It’s easy, it will take you about ten minutes to set up, and after that you will be able to add an affiliate disclaimer to any post with the click of a button. This is how you do it.

Step 1

In my WordPress design tutorials, Step 1 is always to create a child theme. If you have one already – then great – bypass this step. But, if you don’t have a child theme, you need to stop right now and read my post – How to make a child theme & why you need one. In a nutshell, a child theme allows you to create a safe place to put all your design changes so you never risk breaking your theme and your edits are never lost. Follow the steps in that post to create the child theme, and then you can come back here and continue on with this tutorial.

Step 2

If you don’t already use the Advanced Custom Fields plugin, install it. Advanced Custom Fields allows you to add custom fields to any post or page on your site.

Step 3

Click on Custom Fields in the toolbar on the left. You will then be brought to a page of Field Groups. Field Groups are essentially groups of fields that you can target to posts or pages by certain types. For example, you can say that every time you categorize a post under ‘blog’ you want a certain field to appear, or every time a page uses the template ‘full width’ you want other fields to appear. So these groups let us target things.

Create a new Field Group called Affiliate Disclaimer. If you think you might want to come back and add more fields to appear on every post, name it something more general like Standard Posts.

Under Location you will see the conditions that specify how to determine which posts appear where. The default is already set to every post, so you can leave it as is since that is what we want.

Step 4

Next you will see a table, and this is where you add fields. Click Add Field. Under Field Label enter Affiliate Disclaimer.

It will automatically populate the Field Name with affiliate_disclaimer. This is the backend name of the field that you will need later.

Under Field Type select Checkbox.

Under Choices put Display Affiliate Disclaimer : Display Affiliate Disclaimer.

This means that there will be one checkbox, and the option will be Display Affiliate Disclaimer. You can either check the box to display it, or leave the box unchecked.

Lastly, you can set a default. If you use affiliate links a lot and want to automatically have the disclaimer there (but still have the ability to turn it off) you can set the default to be for the disclaimer to show. To do this enter Display Affiliate Disclaimer in the Default Value section.

Step 5

So far we have created the custom field in the backend and configured it. Next we have to make it show up.

Again, if you do not have a child theme, you need to make one before continuing. If you do have a child theme already, log into your FTP. Navigate to your themes folder by going to wp-content > themes. There you will see all the themes installed on your site. You should see your parent theme (the theme you based your child theme on) and your child theme (the theme you created).

Go into your parent theme folder and find the file responsible for single posts. In most cases this file should just be called single.php or something along those lines. Twenty Sixteen is my parent theme, and the content-single.php file is within it, highlighted in the image below.

Affiliate Disclaimer

I can tell this is the right file, because if I type in a bit of text in this file, like HELLO for example, and then save that file and look at a single post on my website, the word HELLO shows up where I want my affiliate disclaimer to show up, like in the image below. So I know I’m in the right place. For your own theme, just do this until you find the right file.

Affiliate Disclaimer

Once you find the right file, copy all of the content that is in it, undo the changes you made, then save and close the file. Now, go back into the themes folder and go into your child theme folder. Right click and make a new file, and name it the exact same thing as the single file you were just in. Save the file, and then open it and paste all the content you copied into it. I also had to put the file in a folder called template-parts, because that’s where it was in my parent theme.

Step 6

Within that file, wherever you want your affiliate disclaimer to appear, you have to paste the following code. Make sure that you don’t paste it between any php tags, or your site won’t work. Each bit of php code that is already in that file has an opening php tag that looks like this . So just make sure you aren’t pasting this code in between any opening and closing tags. Again, the best way to try it is to put in a simple word like HELLO. Then refresh your post, and see where the word HELLO shows up. If that’s the place you want your disclaimer, then paste this code in there.

This code means ‘hey, when I check the Affiliate Disclaimer checkbox, show this text here.’

Affiliate Disclaimer

Step 7

If your Field Name was different than affiliate_disclaimer when you created the custom field, you need to change this code to match yours. It’s just the one instance at the beginning. To double check what your field name is, go to Custom Fields, click edit on the field group you just created, and then look at the field name under the field you just created.

Step 8

Next, spice up your disclaimer, by changing the This post contains affiliate links. to something else. Don’t leave it as just a boring one liner, add some flare. You obviously don’t want your disclaimer to be the exact same as mine, so you should change it up and make it unique to you. After you’ve made any changes save the file.

I’ve also wrapped the disclaimer in a div with the class of affiliate_disclaimer incase you want to style it. I made mine so that it’s italic and a little smaller than the rest of the body text, so it doesn’t stand out too much, and readers can tell it’s not part of the actual content, though it’s still visible and easy to see.

Alternatively, you could decide to just include a short affiliate disclaimer, with a link to a more in depth explanation. And if you really wanted to get fancy you could create an image with the disclaimer in it, and make it what displays when you check the box. That way, the text itself is never seen or extracted as part of your content by the Google Bots.

Step 9

Finally, to see if what you did is working, create a new post or edit an existing post. You should see an Affiliate Disclaimer section on your post editor page. Check the box, and then view the post. You should see the disclaimer text you included now display in the post where you placed the disclaimer.

Affiliate Disclaimer

Now that you’ve spent a little bit of time setting this up, it means that you can add an affiliate link to any post with just the simple click of one button. This makes using affiliate links and making money from your blog that much easier. Good luck!

How do you include affiliate disclaimers in your posts?

17 thoughts on “How to Add an Easy Affiliate Disclaimer to Your WordPress Site”

  1. GREAT tutorial. I’ve been looking for an easy way to do this so my disclosure doesn’t show up in the preview text. You’re a lifesaver! I’m adding this to my mile-long To Do list for the blog. :) PS: Shared it on 3 blogging boards on Pinterest for ya, since it’s so awesome that everyone should see it!
    xoxo, erin |

    1. Thank you Erin, I really appreciate you sharing the post! This is something I struggled with for a while as well and then I thought of this way to do it and had to share! I hope it works well for you. Thanks for reading!

  2. This was very frustrating to setup (looking for the darn single.php file!) but I’m glad I did it. Thanks for the step-by-step tutorial, it was super helpful!

    1. Thanks Jessica, I’m glad you found this post helpful. What did you find difficult about finding the single.php file? Maybe I can add to the post to make it easier for the next person to find!

      1. Im super confused as well. Im stuck on step 5, can you show some pictures and explain where to find the single.php?

        1. Hi Rebecca, I’ve added some more clarification in the post above under Steps 5 and 6, hopefully that will help you find the single.php. Remember, you have to have a child theme created and active to make this work, and logging into FTP the same way you did to create that child theme is where you will find the file.

    1. Hey Lindsey, So you’re looking for the file that corresponds to a single post. It might take some trial and error to find it. It could be called anything based on the theme’s author but they usually try to make things easy to identify, so single, or single post, post, or content maybe. It could also be within another folder. To make sure you’ve found the right one try adding text in the file like ‘test’ then refresh a single blog post. If it shows up somewhere on the blog post then you have found the right one.

  3. I’m a little confused. When I added the single.php file to my child theme and edited with the affiliate disclaimer code, it broke my site (well, all of my individual post pages anyway). This is the code in my single.php file:

    * Genesis Framework.
    * WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
    * Please do all modifications in the form of a child theme.
    * @package Genesis\Templates
    * @author StudioPress
    * @license GPL-2.0+
    * @link

    // This file handles single entries, but only exists for the sake of child theme forward compatibility.

    I tried adding your code before the part where it says "// This file…" That didn't work so I tried adding it after the "genesis();" That didn't work either. I'm not sure what to do.

    1. Hi Kate, Genesis is a framework that makes your site different from one just using WordPress on it’s own, so the process would be different for adding an affiliate disclaimer with Genesis. I’m not familiar with Genesis so I can’t speak to what that process might be. I think the best option for you would be to find a plugin that would do this for you. Thanks for reading and sorry for the confusion!

        1. I was able to do this in GenesisWP, here’s what I added to the functions.php file.

          Thanks for the tutorial Melissa.

  4. Thank you so much for this tutorial! Thankfully my theme provider also provides a Child Theme and I didn’t have to do that part, but this was easy to follow and keeps me from adding an image or the button to my post. Now to edit all my articles. Sharing this now!

  5. Thank you, works great! If anyone is wondering if this works with Divi or Extra Themes from Elegant Themes, I can confirm it does. Single-post.php is your boy!

    Much appreciated.Melissa!

  6. Hey! First of wall, thank you SO much for this post, as well as your post for creating a child theme and finding the FTP stuff. I found them all very helpful!

    Just wondering though, do you happen to have a post showing how to do this with an image instead of the text? Or could you give me a basic rundown to do this? No biggie if not, just thought I’d ask!


Leave a Reply

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