Instantly share code, notes, and snippets.

What would you like to do?
Limitar palabras en Wordrpress
//en functions.php
function trunc($phrase, $max_words, $after = null) {
$phrase_array = explode(' ',$phrase);
if(count($phrase_array) > $max_words && $max_words > 0)
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)) . $after;
return $phrase;
//uso en template
$description = get_term_field( 'description', $term, $taxonomy );
echo trunc($term->description, 40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment