WordPress tip : change excerpt length depending of the category

December 2, 2009 at 9:43 am

Do you ever wished to be able to modify the excerpt length based on which category you are on, without modifying your theme files? If yes, I’m pretty sure you’ll be happy with that recipe.

No need to modify your theme files. Simply paste the code into your functions.php file. Don’t forget to change the category ID on line 3!

add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
    if(in_category(14)) {
        return 13;
    } else {
        return 60;

Thanks to Dave Redfern for contributing to WpRecipes!

Also, that might interest you , PremiumMod are launching a WordPress Theme design contest. Check it out here.