Ronalds Vilciņš

Add reading time to Jekyll without a plugin

You do not need a plugin to show an estimated reading time in Jekyll. Liquid can count the words in a post and divide that number by an assumed reading speed.

This example uses 180 words per minute:

<p>
  {% assign words = content | number_of_words %}
  {% if words < 360 %}
    1 min
  {% else %}
    {{ words | divided_by: 180 }} mins
  {% endif %}
  read
</p>

Posts below 360 words show 1 min read. Longer posts use integer division, so the result is deliberately a rough estimate rather than a stopwatch pretending to be precise.

Use page.content if the snippet is in a layout and content is not giving you the expected value. You can also change 180 to match the reading speed you prefer.

Enjoyed reading this?

If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.

← Back to all articles