Customize the Excerpt by Word Count

Here’s a nice little bit of code that can come in very handy.

If you’re looking to limit the_excerpt() or get_the_excerpt() by a specific word count, here is a great code snippet that you can throw into functions.php that will do just that.

function my_excerpt_length($text){
return 20;
}
add_filter('excerpt_length', 'my_excerpt_length');

function new_excerpt_more($more) {
	return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

Any questions or feedback, please leave them in the comments!

  • Share/Save/Bookmark

Get involved, Vibe with us.

5 Vibes for this post.

  1. I was looking for this today and came accross this bit of code. Does this work with WPMU ans Buddypress?

    Many thanks

    Mark Leonard

  2. Simon says:

    Tried this one out, it only works if you have posts WITHOUT an excerpt, it will get the first number of text specified on the code mentioned above, but when you have POSTED an excerpt, this doesn’t work.

Trackbacks

  1. 11 Awesome Wordpress Development Blogs