There doesn’t appear to be any reference to wp_trim_excerpt() outside of it’s declaration – I’ve checked both the Trac and Xref – when does it work its magic?
Leave a Reply
You must be logged in to post a comment.
There doesn’t appear to be any reference to wp_trim_excerpt() outside of it’s declaration – I’ve checked both the Trac and Xref – when does it work its magic?
You must be logged in to post a comment.
If you’ve already looked in XRef, you’ve seen this comment at the top of the doc block:
So it’s not used in core, but is available for you to use if you need it.
Update
Let me explain a little of what’s going on:
Yes and no.
excerpt_length
andexcerpt_more
are being generated by filters. Here’s the inside of thewp_trim_excerpt()
function:By default,
$excerpt_length
will be set to55
and$excerpt_more
will be set to[...]
. However, you can change this in themes and plugins. Let’s say I wanted to sent the length of trimmed excerpts to be 70 characters instead. I’d use the following code:When I call
wp_trim_excerpt()
later, WordPress will pass that default value of55
in to my filter function. My filter function will then pass70
back andwp_trim_excerpt()
will use that instead.wp_trim_excerpt()
doesn’t set or changeexcerpt_length
orexcerpt_more
when you call it. The function merely uses whatever filters you already have defined for those variables.Further Update
This all depends on how you’re building content. There’s a filter applied to
get_the_excerpt()
that will pass the generated content through thewp_trim_excerpt()
function.So if you hand-write an excerpt, the hand-written content will be passed through unchanged.
If you don’t write an excerpt (
$post->post_excerpt = ''
), the content of the post is passed throughwp_trim_excerpt()
insted, shortened, and returned.For reference, this filter is added on line 147 of
/wp-includes/default-filters.php
: