Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My category descriptions consist of whole pages of content. When I view the manage categories screen, the grid does not truncate the text but rather, shows all of it. I realize I could turn off the description field in "screen options", however, I'd like to be able to truncate the amount of text that shows up there.

How can I execute a filter that limits the amount of text used in this description field?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

That field is not filtered in template.

One way would be to filter get_terms() on that page (but I am not entirely sure that won't break something):

add_action( 'admin_head-edit-tags.php', 'admin_edit_tags' );

function admin_edit_tags() {

    add_filter( 'get_terms', 'admin_trim_category_description', 10, 2 );
}

function admin_trim_category_description( $terms, $taxonomies ) {


    if( 'category' != $taxonomies[0] )
        return $terms;

    foreach( $terms as $key=>$term )
        $terms[$key]->description = substr( $term->description, 0, 50 );

    return $terms;
}
share|improve this answer
    
Works perfectly so far. Only minor issue is that it cuts the content off mid sentence (or mid word in most cases). How would you modify it to cut it off at the first period after n characters? –  Scott B Jan 9 '11 at 13:54
    
@Scott B well, that is realm of regular expression, especially if you mess with HTML (tags and stuff). Maybe you are better off with word count, rather than character count. See source of wp_trim_excerpt() for example of how to do that. –  Rarst Jan 9 '11 at 14:38
    
@Rarst old question is old but: How would I get this to work with custom taxonomy categories? –  Howdy_McGee Aug 6 '13 at 18:07
    
@Howdy_McGee code works against generic terms version of code, so you will probably just need to figure out hook for additional page to run it on, what admin_head-edit-tags.php changes to for custom taxonomy –  Rarst Aug 6 '13 at 19:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.