Thread Starter
grard
(@grard)
I have solved this issue by writing two functions and adding them to functions.php:
function my_post_length($text = null) {
$text = trim( strip_tags( get_the_content() ) );
$word_number = preg_match_all( ‘~\s+~’, “$text “, $m );
return $word_number;
}
add_filter( ‘the_excerpt’, ‘my_trim_excerpt’ );
function my_trim_excerpt( $excerpt )
{
$content = apply_filters( ‘the_content’, get_the_content() );
if (my_post_length() < 34) {
$lastSpacePosition = strrpos($excerpt, ‘ ‘);
$excerpt = substr($excerpt, 0, $lastSpacePosition);
return $excerpt;
}
else return $excerpt;
}
You just have to set your actual excerpt length. In my case it’s =34.