My eBook is 30% off right now: Design Faster, Design Better

Jekyll - Add An Affiliate Disclaimer To Specific Posts

Jekyll - Add An Affiliate Disclaimer To Specific Posts - Cover Image

Published: 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.

Enjoy Reading This Article?

Here are some more articles you might like to read next:

Want To Improve Your Design Skills?

Design Insight is a weekly newsletter filled with design resources, tips, and insights to make you a better designer. It's sent directly to your inbox every Friday.

Click the button below to go to the Design Insight newsletter and sign up.