Ronalds Vilciņš

Show a post's word count in Jekyll

Jekyll can count the words in a post without a plugin. Pass the post content through Liquid’s number_of_words filter:

{% assign word_count = post.content | number_of_words %}
<p>{{ word_count }} words</p>

Use page.content instead of post.content when the snippet is part of a single-post layout. The correct variable depends on where the code runs, but the filter stays the same.

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