Rating: 5 stars
This plugin is a bit over the top for my needs.
I just want a little box to display the number of words in the post (under all the other little boxes on the right side that has Revisions, Tags, Categories, underneath those).
Placed this in my functions.php and it does the trick.
/* START word count post */
function add_word_count_meta_box() {
add_meta_box('word_count_meta_box', 'Word Count', 'word_count_callback', 'post', 'side');
}
function word_count_callback($post) {
// We'll use JavaScript to update this live
echo '<div id="word-count-wrapper">Word Count: <span id="word-count">0</span></div>';
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var updateWordCount = function() {
var content;
if (window.tinymce) {
var editor = tinymce.get('content');
if (editor && editor instanceof tinymce.Editor) {
content = editor.getContent({ format: 'text' });
} else {
content = $('#content').val();
}
} else {
content = $('#content').val();
}
var wordCount = content.split(/\s+/).filter(function(word) {
return word.length > 0;
}).length;
$('#word-count').text(wordCount);
};
// For classic editor
$('#content').on('input', updateWordCount);
// For block editor
if (window.wp && wp.data && wp.data.subscribe) {
var checkForWordCountUpdate = function() {
var content = wp.data.select('core/editor').getEditedPostContent();
var wordCount = content.split(/\s+/).filter(function(word) {
return word.length > 0;
}).length;
$('#word-count').text(wordCount);
};
wp.data.subscribe(checkForWordCountUpdate);
}
// Initial count on page load
updateWordCount();
});
</script>
<?php
}
add_action('add_meta_boxes', 'add_word_count_meta_box');
/* END word count post */
The code provided for the WordPress word count functionality defines a word as any sequence of characters separated by whitespace. Specifically, this is how the word count is calculated:
split(/\s+/)
function in JavaScript is used to split the content of the post into an array of substrings using a regular expression. The \s+
pattern matches any sequence of whitespace characters (spaces, tabs, newlines, etc.).filter(function(word) { return word.length > 0; })
part of the code filters out any empty strings from the array. This is important because the split function can create empty strings if there are spaces at the beginning or end of the text, or multiple spaces in a row.length
property of the resulting array (after splitting and filtering) gives the number of words. Each element of the array represents a word.With this code, a word is any non-empty string of characters that is separated from other words by one or more whitespace characters. This is a common and general way to count words, but it does have limitations. For example, it doesn’t account for words joined by hyphens (like “long-term”) or apostrophes (like “don’t”), which are typically counted as single words. Additionally, numbers or strings of punctuation without spaces would also be counted as words.
This approach is suitable for a general word count feature, but for more advanced or specific word counting rules, the code would need to be adjusted accordingly.
]]>Rating: 1 star
Not good at all, no functionality at all, and a total waste of time. you are better off using the opensource WordPress word count provided
of course, you might get the bells and whistles if you pay, but I would rather use my own FREE code snippets
Rating: 1 star
not all words count. unusable
]]>Rating: 4 stars
Hi, I’m so impressed with this amazing plugin. However, for Chinese bloggers we don’t separate our words with spaces. What we call the word number usually means the character number. So could you please add a feature that can calculate the character numbers (ignore space and punctuation) of all my post? Much thx!
]]>Rating: 5 stars
Thank you!
]]>Rating: 2 stars
We use CornerStone / Pro from Themeco and it seems like the process is having a hard time finding out what is a word and what is not.
WP Word Count’s result is ~1500 words for a ~4500 words page.
We manually compared to make sure.
]]>Rating: 5 stars
Great little plugin!
Easy to use: upload, activate, then open it up and there’s your word count.
So easy even I could do it!
Thanks and keep on keepin’ on …
]]>Rating: 5 stars
Does the trick quickly and easily. Thank you.
]]>Rating: 5 stars
Really appreciate this plugin. Thanks.
]]>Rating: 5 stars
Awesome plugin
I was not expecting so much details like the average word number per month and stuff
This helped me see some writing pattners : for example at the beginning of my blog I used to write around 1200 words per post, and now that I have more time I usually write around 2000 or more words per post ??
PRetty cool stats for me – I am a stats nuts.
NIco.
Rating: 5 stars
well, still works nice!
]]>Rating: 5 stars
thats so amazing…works like a charm on 3.9.1
]]>Rating: 5 stars
I wanted to write a plugin like this, then I researched and found this existing one! It’s great to see how much text I actually have put out there in my time of blogging, like looking down after climbing the first part of a mountain. Nicely done and pretty on top of that.
]]>Rating: 5 stars
What can I say that won’t be a carbon copy of everyone else? Well, that’s impossible because this plugin works flawlessly and does exactly what it says it should do. Install was quick, and it just works. Simple.
]]>