WordPress does have an initially hidden away excerpt section. You can open it up and tinker and set it up via the ‘Screen Options’ normally in the top right. Alas it’s fiddly and normally people just want the first few words of the content to display. A customisable number of words! So here goes!

Firstly go into your functions.php file of your WordPress theme. Add the following at the bottom:

function get_excerpt($count){
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
 // $excerpt = $excerpt.'... more';
  return $excerpt;

Then to display it:

echo get_excerpt(120);

Leave a Reply