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.
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.
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.
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.
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.
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.
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.
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.
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.
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.’
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.
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.
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.
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!