Una forma sencilla de acortar nuestros extractos (cuando queremos que aparezcan en mucha cantidad, o en algún espacio más reducido de nuestro diseño) es añadiendo el siguiente código en functions.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);
}

Seguidamente, nos dirijiremos a nuestro index.php o archive.php y, dentro del Loop, convocaremos la función, sustituyendo el clásico :

the_excerpt();

con un nuevo y a estrenar :


<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>

Siendo aquí aproximadamente 25 las palabras que veremos colectadas.

Un ejemplo completo de Loop en nuestro índice con la implementación hecha en functions.php podría tener entonces este aspecto :

<?php
if (have_posts()) :
while (have_posts()) :
the_post();
?>
<?php the_title(); ?>
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>
<? php endwhile; endif; ?>