Jekyll - Add An Affiliate Disclaimer To Specific Posts

Coding
Written: July 12, 2021
Reading Time: 1 mins

On this website some of the links used are affiliate links. To let people know this, I include a disclaimer at the top of relevant pages.

Instead of manually copying and pasting this text for each new article I write, here’s how I implemented an affiliate disclaimer to specific posts or pages.

In the _includes folder, create a file called affiliate-disclaimer.html

Add the following code to that file:


{% if page.has-affiliate-link %}
<p><i>This article contains affiliate links.</i></p>
{% endif %}

Feel free to change the actual content of the affiliate disclaimer message.

In the _layouts folder, add the code below to any page templates that may have affiliate links. In my case I have 2 files: article.html and book-note.html

This code will include the affiliate disclaimer file to those page templates:


{% include affiliate-disclaimer.html %}

The final step is to include a line of YAML metadata to relevant articles and pages:

has-affiliate-link: true

When this code is added to your pages and articles, it will trigger the first piece of code that includes the affiliate disclaimer text.

If you’re trying to save on load/build times and want to cut down on the amount of includes you use, you could just copy and paste the affiliate-disclaimer.html code directly into your page templates.

Design Insight

A weekly newsletter for creatives with a focus on design. Learn to think like a designer in less than 5 mins a week with curated articles, resources, tools, and insights. Released every Friday to over 180 creators.

I'm Interested!