How to call the_excerpt() with tags or the_content() as an excerpt?

Is it possible to call the_excerpt() with tags intact? I’d like to create a excerpted listing of my posts in a specific category, but I’d also like the links and formatting carried over from the post content.

I’m currently using the_excerpt() which otherwise works fine, however, the tags are stripped out.

I can’t find a filter to place on the_excerpt() to do this, so barring that, is it possible to filter the_content() to pull the first 100 words with tags and a read more link at the end?

1 Answer
1

Actually, I just did something like this for a Drupal site. I based my truncation function on this: Truncate text preserving HTML tags with PHP

Use the final version of the function at the end of the comments. The function takes its $length parameter in characters, not words, but you can probably use the general rule-of-thumb of 5 characters per word to estimate, if needed.

Hook your function to the get_the_excerpt filter, and you should be in pretty good shape.

Leave a Comment