Function - wp_trim_excerpt()
Description - If there isn’t an excerpt for a post this function will create one. It takes the post and strips all the tags out of it so that it is just text. Then it limits the length of it so that you will have a the first 55 words of a post. This way when you go into a category you can see a little piece of the article without having the whole thing until you go to that articles page. So if it’s not what you are looking for you only spent a few seconds getting the just of that article and then you can continue down the page until you find the one you are looking for!
Source -
function wp_trim_excerpt($text) { // Fakes an excerpt if needed
global $post;
if ( ” == $text ) {
$text = get_the_content(”);
$text = apply_filters(’the_content’, $text);
$text = str_replace(’]]>’, ‘]]>’, $text);
$text = strip_tags($text);
$excerpt_length = 55;
$words = explode(’ ‘, $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, ‘[…]’);
$text = implode(’ ‘, $words);
}
}
return $text;
}
Example -
$post = “This is a post about what ever. Lets just imagine that it is over 55 words <a href=’site.com’>Site</a>”;
$excerpt = wp_trim_excerpt(”$post”);
echo $excerpt;
This would return;
This is a post about what ever. Lets just imagine that it is over 55 words…

