This is the code in the PHP file that I put into the widgets folder:
function shorten_cat ($text) {
$chars_limit = 5;
$chars_text = strlen ($text);
$text = substr ($text, 0, $chars_limit);
if ($chars_limit < $chars_text) {
$text = $text . "...";
}
return $text;
}
add_filter ('shorten_cat', 'shorten_cat');
And this is the_category function that I edited:
function the_category( $separator = '', $parents='', $post_id = false ) {
$text = get_the_category_list( $separator, $parents, $post_id );
echo apply_filters ('shorten_cat', '', $text);
}
With this, I get echo'd out an empty space, basically the shortened string does not get returned. I'm not quite sure where exactly the problem lies.
If the string ($text) wouldn't have been inserted correctly into the function, than I probably would have gotten an error that the function expects a string and nothing else, but that error does not occur.
So I'm assuming that the function is not able to return the new shortened string back.
Any ideas how I could accomplish this?