Limit The Excerpt’s Word Count

 In Themes

Limit The Excerpt’s Word Count

One thing that can go wrong in WordPress magazine themes is when users include too many words before the more tag. Sure, they could handcraft the excerpt in the dedicated field, but on a website that has hundreds of posts and on which the text above the more tag has always been used as the excerpt, going back to create excerpts for all of those posts by hand would be cumbersome. In this case, we can limit the number of words shown in the excerpt by using this code:

Here, we’re using a WordPress filter hook, which is a function that parses and (usually) modifies data before it gets stored in the database or displayed on a page. In this case, we’re setting the number of words shown in the excerpt to 10.

Nuno Sarmento
I am full-stack WordPress developer based in London with a wealth of theme development and support experience. I am great at problem solving and developing quick solutions. I specialise in custom WordPress theme development and bug fixing.
Recommended Posts

Leave a Comment

Start typing and press Enter to search