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!











I was looking for this today and came accross this bit of code. Does this work with WPMU ans Buddypress?
Many thanks
Mark Leonard
It should work just the same, I don’t imagine there being any problems with it — but I haven’t tested it to be sure.
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.
You are correct. This is a replacement for the_excerpt(), so you must be using the_content() in order to use this code.