Skip to content

Instantly share code, notes, and snippets.

@emaildano
Last active August 29, 2015 13:59
Show Gist options
  • Save emaildano/10478156 to your computer and use it in GitHub Desktop.
Save emaildano/10478156 to your computer and use it in GitHub Desktop.
Limit by word count excerpts.
// Limit Word Count, Strip Tags from Result
function trunc($phrase, $max_words) {
$phrase_array = explode(' ',strip_tags($phrase));
if(count($phrase_array) > $max_words && $max_words > 0)
;
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...';
return $phrase;
}
<?php $excerpt = get_the_excerpt();
echo '<p>' . trunc($excerpt, 15) . '...</p>';?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment