Thesis offers you a ton of options for using excerpts. The problem is, you can’t control the length and this ugly “[...]” shows up at the end. Let’s get that under control.
Removing The Elipses
This is pretty simple. All we are going to do is use a filter that singles out the “[...]” and replaces it with nothing. Just copy and paste this code into custom_functions.php:
function no_ellipsis($text) {
return str_replace('[...]', '', $text);
}
add_filter('the_excerpt', 'no_ellipsis');
Adjusing The Excerpt Length
Well, this is about as simple as it gets. We insert the parameter $length into the function title. Then, we return the length in number of words contained in the excerpt. The default is 55. I’ve set it to 30 here, but you can set it to whatever you like.
function excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'excerpt_length');
Advanced Excerpt Length Control
You can take this a step further using conditional tags. Let’s say you want different excerpt lengths for your homepage and archive pages. Let’s say you also have a list of posts from a specific category on your homepage and you need a really short excerpt for that. Your code would look like this.
function excerpt_length($length) {
if( is_home() && in_category('featured') ) {
return 10;
} elseif( is_home() && !in_category('featured') ) {
return 70;
} else {
return 40;
}
}
add_filter('the_excerpt', 'excerpt_length');
Once you learn to be creative with conditional tags, you open up a world of possibilities when it comes to serving content dynamically. This is just one example.
Liked this post? Get free updates via RSS when we post or
{ 5 comments… read them below or add one }
Thank you so much Adam for posting the advanced excerpt control snippet! Running through the wordpress codex at 5 am frantically working on a client website I ran across the filter for excerpt length but didn’t think to use conditional tags in the filter itself – gracias!
Thanks… was wondering how to make the excerpt longer, since there’s nothing worse than seeing [...] in the middle of a sentence. Cheers!
Mike,
Making the excerpt longer doesn’t actually get rid of the [...], but the remove ellipsis function does.
Hi Adam, I’m looking for a way to display with Thesis a little excerpt for the comments in the recent comment widget in the sidebar, but I can’t find the way. Could you help me?
Adam, the last code, should read excerpt_length instead of the_excerpt, right?