I’ve been looking for a filter for category_description()
and I have not found any. You could use wp_trim_words()
with category_description()
to get the desired result. For example:
$cat_ID = 4;
// wp_trim_words( $text, $num_words = 55, $more = null );
echo wp_trim_words( category_description( $cat_ID ), 55, '<a href="' . get_category_link( $cat_ID ) . '">' . __("Read more", "text-domain" ) . '</a>' );
Update: I’ve found the filter
add_filter( 'category_description', 'cyb_trim_category_desc', 10, 2 );
function cyb_trim_category_desc( $desc, $cat_id ) {
// wp_trim_words( $text, $num_words = 55, $more = null );
$desc = wp_trim_words( $desc, 55, '<a href="' . get_category_link( $cat_id ) . '">' . __("Read more", "text-domain" ) . '</a>' );
return $desc;
}
Note: if you use the generic the_archive_description()
function in your theme, the above filter works perfectly for categories archvie.