HUGO
Menu
GitHub 90272 stars Mastodon

WordCount

Returns the number of words in the content of the given page.
Syntax
PAGE.WordCount
Returns
int

Usage

The WordCount method on a Page object returns the number of words in the content of the given page, excluding HTML tags. If CJK word counting rules apply to the page, the method counts each CJK character as a word.

To round up to the nearest multiple of 100, use the FuzzyWordCount method. To count the words in a string, use the strings.CountWords function.

For content in CJK languages, set hasCJKLanguage to true in your project configuration. When enabled, Hugo applies CJK word counting rules to pages containing CJK characters. To override this behavior on a given page, set the isCJKLanguage field in its front matter.

Examples

{{ .WordCount }} → 103

A page that contains Chinese characters, with CJK word counting rules enabled in front matter:

content/example.md
---
title: Example
isCJKLanguage: true
---

Hugo 是一个静态网站生成器

Counting words in the page above:

{{ .WordCount }} → 11