Individual Excerpt lengths in BranfordMagazine

BranfordMagazine and also my other themes use the excerpt template tag for auto-shortening texts on the homepage and in other areas. This is nothing spectacular since many themes do it like that. But BranfordMagazine uses the power of WordPress 2.9x to provide a function for individual excerpt lengths. Be aware that this doesn´t work with WP versions prior to 2.9. By default this is used for shorter excerpts in the featured articles section. Of course you can use this technique with any of my premium WordPress themes.

How to use individual excerpt lengths

Open your functions.php file in the theme directory and look up the code below. You will see this (or a similar) function:

 //modify the excerpt lenght (WordPress default is 55 words)
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
        return 35; // change to 35 words
    }

I think it´s more or less self explaining. By default (and based on my demo site) it means that the excerpt of category 4 (featured articles) is limited to 25 words. The excerpt of any other category is limited to 55 words which is the WordPress default. Now you can easily change the lenght of your excerpts just by changing the numbers 25 and/or 55 to whatever you like.

Extending the function

You can also extend this function to archieve other categories to display different excerpt lengths. Try something like this:

 //modify the excerpt lenght (WordPress default is 55 words)
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
	if (is_archive()) {
		return 35; // This is the number of words in archive pages (e.g. category overview). 
    } else {
        return 55; // This is the number of words in all other excerpts
    }
}

It´s up to you now. Play around with it.