Change WordPress Excerpt Length Depending of the Category

WPRecipes has featured a useful example on how to change wordpress excerpt length depending on which category you are on. This is important for some webmaster who likes variations on their excerpt length depending on different categories. Let’s taste the recipes.

 

Simply paste the code below into your functions.php file. Don’t forget to change the category ID on line 3!

[sourcecode language=’php’] add_filter(‘excerpt_length’, ‘my_excerpt_length’);
function my_excerpt_length($length) {
if(in_category(14)) {
return 13;
} else {
return 60;
}
} [/sourcecode]

 

The above code tells the excerpt length to change to 13 when the category is on category 14. Otherwise the length will be default at length of 60.

Thanks for this great hack WPRecipes!