I'm trying to learn HOW to learn about WordPress by following its source code etc.

I'm really stumped at the_excerpt(). Documentation states that the_excerpt uses get_the_excerpt(), and will return either the (manual) excerpt, or will use the first 55 characters of the_content.

I'm interested in the logic that looks first for the manual excerpt and then decides whether it needs to go in and extract a substring from the post content. But I can't find it.

In post-template.php, we see the_excerpt() and get_the_excerpt() defined.

the_excerpt() does nothing more than echo out get_the_excerpt():

249 function the_excerpt() {
250         echo apply_filters('the_excerpt', get_the_excerpt());
251 }

get_the_excerpt() seems to do nothing more than grab the post_excerpt column from the wp_post table:

261 function get_the_excerpt( $deprecated = '' ) {
262         if ( !empty( $deprecated ) )
263                 _deprecated_argument( __FUNCTION__, '2.3' );
265         global $post;
266         $output = $post->post_excerpt;
267         if ( post_password_required($post) ) {
268                 $output = __('There is no excerpt because this is a protected post.');
269                 return $output;
270         }
272         return apply_filters('get_the_excerpt', $output);
273 }

I don't see where the logic to grab $post->post_content resides. Is it in the filters? I can't see those filters defined anywhere, but this may be because I just don't know where to look.

A cursory glance at Adam Brown's source code search site doesn't seem to be turning up any definitions either.

Can someone help me pick up the thread and figure this out? Remember, I'm more interested in how to figure it out than I am in the actual answer.

I appreciate everyone's input.


1 Answer 1


From what I understand in the default-filters.php file a filter is applied to the 'get_the_filter' filter. The callback is for a method called 'wp_trim_execrpt'. This is found in formatting.php. From there you can see the logic. Hope that helps.

  • Hey Phoenix, I think you're on to something. For my learning though can you tell me: what gave you the idea to look in default-filters.php?
    – Tom Auger
    Commented Apr 21, 2011 at 19:47
  • I use netbeans so I can quickly jump to the function within wordpress (rather than looking on the codex). I traced it back from the apply_filters('get_the_excerpt'). If there is an apply, then there must be an add_filter('get_the_excerpt', 'method_here'). So I just searched for add_filter( 'get_the_excerpt' and bam, there it is :)
    – Cristian
    Commented Apr 21, 2011 at 20:11
  • You da man. I will have to look into netbeans - I know nothing about it. Appreciate the insight!
    – Tom Auger
    Commented Apr 21, 2011 at 20:28
  • @tom you're most welcome buddy, it's what this site is for :)
    – Cristian
    Commented Apr 21, 2011 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.