Limit Word Count in WordPress Excerpt

Word-limited Post Excerpts

I came across a great way to limit the number of words displayed in the excerpt for a WordPress post, brought to you by the good folks at Cuppa (update – link removed because the site is gone). This method will allow you to choose a specific word limit every time you use the_excerpt or get_the_excerpt in your template files, making it extremely versatile and easy to use. You could even set the word count to a variable if you were so inclined, so you could change the count dynamically depending on your needs.

 

All you have to do is open up your functions.php file for your theme and enter the following code:

The following code is then used to replace

or just to display anywhere you want this word-limited excerpt to appear.

You just replace 30 with the number of words you wish to limit the excerpt to. It’s quite simple! For more information, be sure to check out the original post.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.

7 Comments on “Limit Word Count in WordPress Excerpt”

  1. hello
    thanks for this solution
    the issue now is that the “read more ” or “…” is no longer showing

    is there a way i can add it

  2. Please my concern might not be relevant to the topic but i recently discovered that my word count on my wordpress posts (title field) is beginning to count from 30. how do i overcome this please. thanks for a quick reply.

Leave a Reply

Your email address will not be published. Required fields are marked *