Remove images from get_the_excerpt

If you read the Codex entry for get_the_excerpt(), you will find this:

If the post does not have an excerpt, this function applies wp_trim_excerpt to the post content and returns that generated string with “[…]” at the end. wp_trim_excerpt is applied via the get_the_excerpt filter and can be removed.

The wp_trim_excerpt() function:

Generates an excerpt from the content, if needed.

The excerpt word amount will be 55 words and if the amount is greater
than that, then the string ‘ […]’ will be appended to the excerpt.
If the string is less than 55 words, then the content will be returned
as is.

So, you could either re-apply wp_trim_excerpt() to the get_the_excerpt filter, or else just output it directly:

   $html .= "

   <article>
   <span class=\"date\">" . get_the_date() . "</span>
   <h2><a href=\"" . get_permalink() . "\">" . get_the_title() . "</a></h2>
   " . wp_trim_excerpt() . "
   </article>
   ";

Leave a Comment