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.
Related articles
- The HTTP Status Codes I Actually Check
A practical guide to common HTTP response codes, redirects, client and server errors, and the headers that explain them.
- What Makes a Website a Progressive Web App?
A practical look at service workers, web app manifests, installation, and the cases where a Progressive Web App is worth building.
- What a Static Site Generator Actually Does
A static site generator combines content and templates before deployment, producing HTML files that a web server can deliver directly.