Let’s say you want to display you most recent post in a custom template, maybe the front page. You want to display the post title and an excerpt. But what if there is no manual excerpt? Well then we’ll fall back to using the_content with a limit on the number of characters and suppress the display of any shortcodes.
Here’s the code:
Notice we’re using wp_trim_words()
and strip_shortcodes
functions to achieve an automatic excerpt with only text.