BlogWordpress function to limit excerpt by number of words

8th September 2013

Quick snippet of code to replace the_excerpt() which allows you to define the length of the excerpt in words...

// Custom excerpt length function - limit excerpt by number of words function excerpt($len = 54){   return implode(' ', array_slice(explode(' ', get_the_excerpt()), 0, $len)); }

Pop this in functions.php and wherever you'd normally put...

the_excerpt()

Put this instead...

echo excerpt(12) // 12 is the number of words

Let's Talk