Skip to content


WordPress: Change excerpt length depending of the category December 18, 2009

Posted in How To, Wordpress. 157 views

No comments

By default, excerpt length is set to 55 words. To change excerpt length using excerpt_length filter, you need to add a dew code to your functions.php file in your theme. You can modify the excerpt length based on which category you are on, without modifying your theme files.

You don’ have 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;
}
}

If you enjoyed this post, please share!


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.

Powered by WP Hashcash