Using the WordPress excerpt correctly

There are a number of ways in which post excerpts can be manipulated in WordPress. The hooks and filters available have improved greatly over the years.

The complicated version 2.8 way
Back in 2009 you would have to roll out your own function. Grabbing the content and doing some rudimentary word counting yourself.

function tcb_the_content($limit) {
  $content = explode(' ', get_the_content(), $limit);
  if (count($content)>=$limit) {
    $content = implode(' ',$content).'...';
  else {
    $content = implode(' ',$content);
  $content = preg_replace('/\[.+\]/','',  $content);
  $content = apply_filters('the_content', $content);
  $content = str_replace(']]>', ']]>', $content);
  return $content;

That’s 14 lines of code. Not too much, but the main issue is that it is a hack. It replaces core code. And when you replace core code rather than work with it, you lose out when core gets updated. Not good.

The easy version 2.9 way
Since version 2.9 it has been a trivial exercise in the use of filters.

function tcb_new_excerpt_length($length) { return 20; }
add_filter('excerpt_length', 'tcb_new_excerpt_length');

Doing without excerpts.
Often simple things like this disappear, because they simply are not needed. And quite possibly, with the use of more tags, there is no need to fuss around with the excerpt size any more. A simple and small comment in the main post body can be used to mark the excerpt.


Do you think the excerpt is needed any more?