最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to return the_excerpt (without echo)?

programmeradmin2浏览0评论

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?

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 asked Mar 31, 2011 at 15:12 prabhaspprabhasp 1331 silver badge3 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 5

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.

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

发布评论

评论列表(0)

  1. 暂无评论