Skip to main content
3 of 4
Added strip_tags().
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Just count the spaces and add 1:

// No need to count markup.
$text        = trim( strip_tags( get_the_content() ) );
$word_number = substr_count( $text, ' ' ) + 1;

Another way, taking the old American double space tradition into account:

$word_number = preg_match_all( '~\s+~', $text, $m ) + 1;
fuxia
  • 107.1k
  • 38
  • 255
  • 459