It counts all the words within your target element. In the example above, we target a .post-content class selector.
The word count includes all text elements (headings, paragraphs, lists, blockquotes etc.). Everything relevant.
It excludes whitespace, commas etc.
Replace the .post-content class with whatever class, id, or element selector you have for your posts or pages.
Note: you can use getElementsByClassName() instead of querySelectorAll().
You test can with the code in your favorite browser’s console, or on this CodePen.
Has this been helpful? Let me know in the comments!