Posted by KaiseRCrazY on 9th October 2009

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!

  • del.icio.us
  • Digg
  • Facebook
  • FriendFeed
  • Reddit
  • StumbleUpon
  • Technorati
  • PDF
  • Print

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

No comments yet!

Post your comments