Add Word Count & Estimated Reading Time to Posts

It’s all the trend these days to add “reading time” or a word count on your blog posts to indicate how big they are. We often add a word count as it’s super easy to add to your Hugo site (except we don’t on this site - oops!)

Word Count

We can use word counts in our theme template. We’ve shown the likely file below, but might change based on your theme and setup.

File: themes/{theme-name}/layouts/_default/single.html

{{ .WordCount }} words

Example: 115 words

Estimated Reading Time

The simplest way is to use Hugo’s built-in reading time, like belo:w

{{ .ReadingTime }} minutes

Example: 2 minutes

Alternative Way (including seconds):

We can use the word count to produce an estimated reading time for you post. This is based on the assumption that the average person reads about 200-250 words per minute.

{{ $readTime := mul (div (countwords .Content) 220.0) 60 }}
    {{ math.Floor (div $readTime 60) }} minutes 
    and {{ mod $readTime 60 }} seconds.

Example: 2 minutes and 47 seconds.

There we have it - a how to on adding word count and reading times to your Hugo blog posts - good luck!