Function to limit the words or characters in a post excerpt
Description
This function will limit the number words or characters in a post excerpt. Change “XY” to the number of the desired charaters
This function will limit the number words or characters in a post excerpt. Change “XY” to the number of the desired charaters
HTML Source Code
<!--limits the words-->
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>
<!--limits the characters-->
<?php echo substr(get_the_excerpt(),0,XY); ?>
PHP Source Code
<?php
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
?>