WpCode.net

Daily Wordpress Code Snippet

How to Truncate Category Description Content

| 0 comments

Pin It

As you probably know, you can add a category description from the categories tab, but if it is so long, you can truncate it using and pasting the following code to your function.php file. This will hide the description only in the wordpress backend- Continue reading

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, 150 );
    return $terms;
}

Leave a Reply

Required fields are marked *.

*