Limit word in the front widget


<?php echo limit_words(get_the_excerpt(), ‘5’); ?>


function limit_words($string, $word_limit) {
$words = explode(‘ ‘, $string);
// this next bit chops the $words array and sticks it back together
// starting at the first word ‘0’ and ending at the $word_limit
// the $word_limit which is passed in the function will be the number
// of words we want to use
// implode glues the chopped up array back together using a space character
return implode(‘ ‘, array_slice($words, 0, $word_limit));


Posted in Wordpress