
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.

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.
7 Responses
What a great idea! I don’t have any ideas right now of how to use this, but it’s still pretty cool.
Yah for my tip being published. thanks!
@Eric B. I find it very useful because when i have categories for news, events, blog etc they always need different lengths because they have different designs. This tip is more for when using Wordpress as a cms rather than blogging platform.
Cool Tip & Agreed with Dave.. really useful when using Wordpress as CMS.. a really great one for article and news sites !
Thx Dave, its help me when i need to display excerpt in fix box or something
Very useful, thanks… Great blog
I love it!
Trackbacks: