Two Useful Tips For Thesis Excerpts

As you know 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.

Thesis Excerpts

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 25 here, but you can set it to whatever you like.

function excerpt_length($length) {
	return 25;
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.

Leave a Reply

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