Automatically Add an Affiliate Disclaimer to Your WordPress Posts

Disclaimer: This post contains affiliate links, which means I may earn some money if you click on one.
Read the full dislcaimer.

It’s super important to have clear and visible affiliate disclaimers on your website or posts that include affiliate links that you can earn money from. Whenever I have a post that contains such links, there is a disclaimer at the top with a link to my full affiliate disclaimer page.

But posting this sentence every single time can be annoying and time-consuming, plus you might accidentally forget! That’s why all I have to do is tag my post and the disclaimer gets automatically added to my post. Learn how in my post below!

Put this code in your functions.php

To start automatically adding a disclaimer to your posts, all you have to do is copy the code below and paste it in the very bottom of your theme’s functions.php file.

If you’re scratching your head, don’t worry! Editing your theme’s files can be scary. And I’ll be honest, if you paste one wrong character in your functions.php you can break your entire website. 

Helpful Tip: Use the My Custom Functions plugin so you don’t have to edit your theme’s file.

To find this file, go to Appearance > Theme Editor and click on the functions.php from the list of files to the right. Copy and paste this entire file into a Notepad doc just in case. Scroll down to the very bottom of the file, skip several lines so you have some space and post the code below.

function affiliate_the_content( $content ) {

 if( is_single() ) {
      if (has_tag('affiliate')) {

    $custom_content = '<div class="disclaimer">This post contains affiliate links, which means I may earn some money if you click on one. <a href="/affiliate-disclaimer">Read the full disclaimer here.</a></div>';

	    $custom_content .= $content;
    return $custom_content;
add_filter( 'the_content', 'affiliate_the_content' );

Save your file and everything should be the same. Except now you can tag any post with “Affiliate” and your sentence will be added to the very top.

The code has my own sentence and links to an affiliate disclaimer page, but you can edit it to say whatever you like or change your page URL.

If you want to style this sentence to look different or stand out, all you have to do is target the class disclaimer in your CSS.

Want to change the URL or add your own disclaimer page? Simply add your disclaimer page’s URL in the quotations after href. So instead of /affiliate-disclaimer you might put

Uh oh, it’s broken

So what do you do if you happen to break your website with your functions.php? Well you’re going to have to go into your theme’s files via FTP or access the file in your host’s file manager. Just go to your web host, like SiteGround, and search in their support or help section. 

I use FileZilla for FTP, it’s free and highly rated. Once you’ve either connected to your website in FileZilla or opened up the file manager, navigate to wp-content (or public_html or whatever your main WordPress folder is called) > themes > your current theme > functions.php.

Download it to your PC! Then copy the code from the doc you created at the beginning and paste it over this file. Then reupload it to the server and voila! Your site should be back to normal.

Rather a plugin?

If you don’t want to fool with adding your own affiliate disclaimers with code, my friend Ashley has a plugin that does the same thing!

Just go here to download the affiliate disclaimer plugin and then navigate to your WordPress plugins area. Up top you’ll click Upload and add the file you just got. Simple!

I love making things work easier and faster in WordPress and there’s no shortage of quick functions you can add to your own website. Let me know in the comments if you have trouble or if this tutorial helped you out!

Affiliate Link Tracker
Affiliate Link Tracker

Free spreadsheet to track all your affiliate programs, links, and logins

Enjoyed this? Please consider sharing πŸ’•

Automatically Add an Affiliate Disclaimer to Your WordPress Posts
Heya, I'm Shaylee!

Heya, I'm Shaylee!

When I'm not stuffing my face with sushi or being forced into dog pets I help bloggers and business owners tackle the tech and make WordPress less confusing.

Find Out More

46 thoughts on “Automatically Add an Affiliate Disclaimer to Your WordPress Posts”

  1. Good day, Shaylee. I just wanted to thank you so much for this post. I was hoping there was a way to do this without having to input the information every time I made a post. I was curious, is it possible to do two of these but with different tags? I am not using affiliates at the moment (not even public yet!) but plan to eventually, so I’d need something like this for that; but I also want to add a disclaimer to the top of certain posts that aren’t affiliate posts but still need a disclaimer. Thank you so much for providing this resource for us! πŸ™‚

    • Yup, you can use this for anything you would need to add to the top of a post. You can change the tag from affiliate to anything you like. Just be sure the change “affiliate” to “your-word” in the code.

      • Thank you so much! I just put in the code and tested it out – works like a charm! πŸ™‚ I appreciate you getting back with me and for sharing this code with us. It’ll make things so much easier!

      • Well, you did an excellent job! I have implemented this on my site with no issues and shared it. The only part I personally got hung up on for a second was the disclaimer page. I thought, ok I know how to create a page, but how am I going to get it to link with the code. Then I realized if the page was titled the exact same as you have in the code it would work. Sure enough it did.

        If anything, maybe add that in there that people can specifically create a new page titled…and that will automatically be linked. Hope that helps!

  2. Thanks so much for this information!! I just happened upon this post via pinterest and am glad I stopped in to check it out. I now have an “automated” system for my affiliate disclaimer and I even managed to figure out how to set up one for my specific Amazon disclaimer so they’ll be happy. I’m so new to this but surprised at how much I’m learning, thanks to the generosity of fellow bloggers like yourself. Thanks, again!

  3. Thank you so much! I’m still super new to blogging and changing the code, so this is very helpful.

    What part of the code would I change to have this insert at the bottom of the post instead of the top?
    What part would I change to make the text italicized?

    Thanks again! πŸ™‚

    • I’m so glad it helped, Tess! And welcome to the blogging world πŸ˜€

      I made the disclaimer appear at the top of the post because it’s typically required to include the disclaimer before the affiliate link. If you want to italicize the text you would wrap your text in these: < em> This is italics < /em> But without the spaces πŸ™‚

    • Hey Mary-Anne! For pages all you have to do is copy the code, starting with the div tag, that contains the disclaimer text. Then just paste it into the text editor on the page you want it on. Or you can use the plugin mentioned above and it will produce a shortcode for you.

    • Hey Shafi! It’s totally possible to do this with it appearing below the post, but because of FTC guidelines the disclaimer needs to appear before the link does, which is why I have it at the top.

  4. I did this. It didn’t work and now I get this error. Your PHP code changes were rolled back due to an error on line 235 of file wp-content/themes/tiffany-pro/functions.php. Please fix and try saving again.

    syntax error, unexpected end of file

    • Hey Mandy! If you want to copy/paste the contents of your functions.php file into a PasteBin ( I’d be happy to check it out. It’s hard to tell what the error could be without looking at the code. I use this in my own functions and haven’t had any problems.

      • It looks like you have an extra } at the very end of the file. Removing that should fix it πŸ™‚ If you plan on just using the plugin then you can go ahead and remove all the code (starting at function affiliate_the_content…)

  5. Thank you for writing this post! It was helpful. I’d like to know though how to go about making the disclaimer in a smaller text size or font? I really like the way you have yours but I’m just unsure how to do it. Can you help me? Thanks in advance!

  6. Thanks, this was helpful. I thought I was going to have to type the disclaimer on each post. I have a tip for people who don’t want to go into functions.php themselves. I used a plugin called Code Snippets to insert the code. With it, I’m able to insert code, give it a name, and have it work perfectly. This makes it easier to find later if I have to deactivate it later, which I can do at the press of a button.

  7. Thank you for this helpful article but I wanted to let you know that I also experienced this specific code error when I tried to enter above in the functions php=
    syntax error, unexpected ‘if’ (T_IF)

    can you please help with that? I use the extra theme. Not sure if that makes any difference.

    • You would need to replace your functions.php file with the backup you made or the original from your theme. If you look under “Uh oh, it’s broken” in the post above I talk about it a little more πŸ™‚

  8. I just had to pop in because I’ve had this post bookmarked as a to-do for ages, but I finally came back and actually did it and I’m so glad I did! Thank you for sharing this – your code was the only snippet I could find that actually made sense (and/or didn’t require a plugin – ugh!). It’s so straightforward and simple, but I never would have thought to filter based on a tag, so I appreciate you sharing your knowledge. πŸ™‚

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.