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:

add_filter('excerpt_length', 'ns_excerpt_length');
function ns_excerpt_length( $length ){
 return 10;

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.

Recommended Posts

Leave a Comment

Start typing and press Enter to search

Let's work together

I'd love to work with you! Please fill out my project form to tell me more about your project/work. I reply to all enquiries within 48 hours.
Or call me on 07930 194000.


  • March - Booked
  • April - Limited
  • May - Limited


  • My day rate is £300.
  • I can provide a fixed price for your work.
  • Projects start at around £2,000.

Enquiry Form