Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hey all, I see that get_the_excerpt() echoes the post excerpt if it is manually set, but not if it is automatically generated (with just the 55 words, for example). [and its use is deprecated]

the_excerpt() on the other hand, echoes directly without giving me a string in return.

Is there a function to return the excerpt of a post in Wordpress, including automatic excerpt if not manually defined, without echoing it?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

Sure thing my friend, you see, the function "the_excerpt" (located at "WORDPRESSINSTALLDIR/wp-includes/post-template.php") is the one that makes the echo:

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

so, what you want is to use the same function "apply_filters" without the echo:

$myexcerpt = apply_filters('the_excerpt', get_the_excerpt());

...and there you have your excerpt.

share|improve this answer
add comment

There's also the function wp_trim_excerpt(), which will generate and return an excerpt for the current post.

share|improve this answer
    
Thanks, so wp_trim_excerpt(get_the_excerpt()) would also work for my purpose. However, I ended up going with the apply_filters solution, because I also have another plugin messing with excerpts installed. –  prabhasp Mar 31 '11 at 18:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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