Archived

Add an Affiliate Disclosure Statement using Advanced Custom Fields

Updated

Written by

Dave Warfel

Reading Time

4 minutes

If you buy something from one of our links, we may earn a commission.

WP Smackdown is made possible by advertising & affiliate revenue. Eventually, we plan to offer video courses, sell ebooks, and possibly go down the membership route to offer up paid content. But for now, affiliates help keep us in the business of writing great content.

The FTC is very clear on disclosing the relationship that people & businesses have with affiliates, especially when it comes to writing reviews and/or recommending products (both of which we do on this site). In addition to abiding by the rules that the FTC has put in place, we want to be completely transparent & honest with our readers. With that being said, you might see an affiliate disclosure statement at the top of some articles.

Before We Start

When thinking about how to setup our affiliate disclosure statement, we pondered the following:

  • Should we use the same language on every page, or modify the disclosure based on the article content?
  • If the FTC changes their rules, or we decide to change the disclosure, how easy will it be to update everywhere?
  • How do we honestly & obviously display a disclosure without it getting in the way of our actual content?
  • How can we say what we need to say… keep it short… and still provide the full details behind our relationship with affiliates?
  • What tool(s) should we use to implement our disclosure?

Our Solution: Advanced Custom Fields (ACF)

With all of these questions answered, we decided on Advanced Custom Fields for implementing our affiliate disclosure statement. We chose it because…

  • we already use it for other things
  • it’s incredibly well-built, popular, and supported
  • it allows for a global implementation, but is flexible enough to allow for custom messages down the road
  • we fully control the markup & styles
  • it wouldn’t take much time to setup

Creating an Affiliate Disclosure using Advanced Custom Fields (ACF)

1. Setup a new field in ACF

Affiliate Disclosure ACF Settings Page
The ACF settings for our affiliate disclosure. Click image for full size
  1. Navigate to Custom Fields > Custom Fields
  2. Add a new field group. We chose to name it “Affiliate Disclaimer.”
  3. You’ll want to use the following settings:
    • Field Type: Checkbox
    • Required?: No
    • Choices
      • yes : Yes
    • Layout: Horizontal
    • Set your Location settings to whatever meets your needs. We are just showing it on all articles with a post type of “post.”
    • Options are completely up to you

After saving those settings, you should end up with something like this:

Affiliate Disclosure Meta Box
The affiliate disclosure statement meta box on the post edit screen

2. Add the Affiliate Disclosure in your Template

Now that we have the field showing on our post edit screen, we have the option to check Yes. Now we need to tell our template to output some markup if Yes is selected. We added the following code to our single.php template, just before the call to the_content().

<?php /* insert affiliate disclosure */
$affiliate_disclaimer = get_field( 'acf_affiliate_disclaimer' );
if( in_array( 'yes', $affiliate_disclaimer ) ) { ?>
	<p class="disclaimer"><strong>Disclosure:</strong> This page contains affiliate links. If you purchase a product from one of our links, we could receive a commission from the seller. Rest assured, we only recommend products we believe in, and all opinions are 100% truthful. <a class="nowrap" href="/legal/#affiliate"><small>Learn More &raquo;</small></a></p>
<?php } /* end affiliate disclosure */ ?>

A few notes about the code

  • The $affiliate_disclaimer variable can be set to whatever you want. Just make sure you use the same variable within the if() statement.
  • acf_affiliate_disclaimer must match the “Field Name” set in ACF
  • Feel free to customize your markup. We chose to keep things simple: <p> tag with a class of “disclaimer”
  • Add whatever styles you need to your theme’s style.css file

3. The Result

Here’s what our affiliate disclosure looks like.

Affiliate Disclosure Example
This is how our affiliate disclosure looks

Notes about our disclosure

  • We followed the FTC’s guidelines in keeping the font-size the same as the main content, as well as highlighting it in some way (blue border)
  • We added an additional hover style to make it stand out more, but only when the user was interacting with it
  • Because we wanted to include more information, but not get in the way of the article’s main content, we added a “Learn More” link. We used CSS to only show this link when the user seemed interested in the disclosure (by hovering over it).

If you’re not using an affiliate disclosure statement on affiliate articles, I highly recommend you do so. As affiliate marketing becomes more and more popular, the FTC is cracking down on publishers who aren’t following their guidelines.

Are you using a plugin to display your affiliate disclosure statement, or did you opt for the non-plugin route? Please share your ideas & setup in the comments.

Dave Warfel

LinkedIn  •  X (Twitter)Dave has been working with WordPress since 2011. He's built 100s of client sites and almost a dozen of his own. He's tested almost every plugin you can think of, hosted with at least 10 different companies, and gone down every SEO rabbit hole you can imagine. When's he's not tinkering with new software, you'll find him in the mountains of Colorado, trail running, summiting peaks, and rippin' downhills on his mountain bike. 🏔️🏃🚴🤸

14 responses to “Add an Affiliate Disclosure Statement using Advanced Custom Fields”

  1. Angela Andrieux Avatar
    Angela Andrieux

    Great article and solution – it got me about 90% to where I want to be. However, can you add any insight on how you created your formatting with CSS? Thanks!

    1. Dave Warfel Avatar

      Hi Angela — Sure. I’d be happy to.

      I added a class of “disclaimer” to the <p> tag, and then I applied CSS styles to that class in my stylesheet.

      You can see the “disclaimer” class applied here:

      <p class="disclaimer">

      From there, you would then open up your stylesheet (style.css)—or use the Customizer’s “Additional CSS” feature—and add the styles you want. I would recommend using a little bit of padding, and then either a background-color or border… or both. Aside from padding, the rest is up to you. Here’s an example that would create a green background color with white text:

      .disclaimer {
      	padding: 0.75rem 1rem;
      	background: #00a886;
      	color: #fff;
      }

      Please let me know if that answers your question, or if you need any further help.

    2. Angela Andrieux Avatar
      Angela Andrieux

      Thank you so much for the followup! That was exactly the help I needed. :) You rock!

  2. Karl Avatar
    Karl

    Good tips, thank you. I had an error when I tried to implement this though.

    Warning: in_array() expects parameter 2 to be array, boolean given

    I was able to fix it by changing the output in ACF to TRUE : Yes and changed the third line of code to:

    if( $affiliate_disclaimer ) { ?>

    This way, I was creating a TRUE/FALSE in $affiliate_disclaimer and doing a simple if statement.

    Thanks!

    1. Dave Warfel Avatar

      Thanks for chiming in, Karl. I’m not sure why I’m able to get it to work and you were getting an error, but I’m glad you figured it out. And thanks for sharing your solution for others who might run into the same issue.

    2. Violet Avatar
      Violet

      Hi, Karl! Can you please copy paste the whole code you used? I have the same problem, but can’t figure it out. Thanks a lot! Violet.

  3. Julia Avatar
    Julia

    I have followed step 1 to a T. I am struggling on step 2, specifically, adding code to the single.php template, just before the call to the_content().

    Where do I find the single.php template?

    I’m new to WordPress, so forgive me if this is a novice question!

    1. Julia Avatar
      Julia

      Ok, I found it in Appearance -> Editor.

      I wasn’t sure where to paste the code. I put it just after the header and before a section of code that contained the word content.

      I then went to a draft post, checked the box to indicate “yes” and typed in a few words for the draft. When I previewed the post the disclaimer was not there. I also tried adding the disclaimer to a previously published post. No success.

      What could I have done wrong?

    2. Dave Warfel Avatar

      Hi Julia —

      Nice detective work finding single.php. That is the correct file. I’m guessing there’s a small error in the code somewhere.

      Can you send me the code you’re using? Copy/Paste it from the file and email it to [email protected]. Also, if you could include a screenshot of some of the code before & after it, that will help me see if it’s in the right place.

      Thanks.

  4. BlogaLiving Avatar
    BlogaLiving

    You say “without a plugin” and then it’s all about the plugin you use. Please don’t say “without a plugin” unless you mean we don’t have to add a plugin to accomplish the outcome. We don’t all use this plugin.

    1. Dave Warfel Avatar

      My bad. I updated the article’s title and one of the headers within the article to remove the “without a plugin” language. Thanks for pointing it out.

  5. BlogaLiving Avatar
    BlogaLiving

    Thank you.

  6. Marko Bakic Avatar
    Marko Bakic

    Hi Dave, my single.php is a bit different:
    <?php
    /**
    * Author: Andrei Baicus
    * Created on: 28/08/2018
    *
    * @package Neve
    */

    $container_class = apply_filters( 'neve_container_class_filter', 'container', 'single-post' );

    get_header();

    ?>
    <div class=" single-post-container">

    <article id="post-"
    class="">

    <?php
    get_footer();

    Could you let me know where exactly to insert your code?

    Thanks!

    1. Dave Warfel Avatar

      Hi Marko – That looks like your single.php file is missing some things. If you are unsure where to place the code, I recommend you ask your theme developer how to insert custom fields where you want them to appear. They should be able to direct you to the correct file. And there, you can just use the code in this tutorial.

Leave a Comment