Show word counts on your posts!
I konw there are some plugin about that but you can do that with a simple code. No need plugins. If you want to add some attractive code to show word count on your posts only edit two file and use a short-code…
Here is the code;
We will change your theme’s functions.php and single.php, because of this wou need to make the backup this files. First the code of functions.php;
function count_words($str){
$words = 0;
$str = eregi_replace(" +", " ", $str);
$array = explode(" ", $str);
for($i=0;$i < count($array);$i++)
{
if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i]))
$words++;
}
return $words;
}
Here is the code of sinlge.php;
Word count: <?php echo count_words($post->post_content); ?>
After you placed this code to single.php the code count your words.
That’s all. Have a nice day!
- Wordpress















Made by Symmetric Web
Distributed by Smashing Magazine
No comments yet!