X

How to Limit the Characters for Category Description in WordPress

Snippets by IsItWP

Do you want to limit the characters for your category description in WordPress? WordPress allows you to add descriptions for your categories, which is usually displayed on your archive pages. Here’s the code snippet that helps you limit the characters in your category description with the WordPress admin panel.

Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin.

truncate description within categories admin panel

Adding this snippet to the functions.php of your wordpress theme will truncate the description displayed within the categories admin panel to 150 characters. Change the number 150 on line 09 to adjust the number of characters for the category description.

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;
}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.

Comments   Leave a Reply

  1. Your opt-in is not working. I tried with 2 emails and never got your email.

    1. Melinda Bartley August 16, 2023 at 8:55 am

      Hi Dalia,

      Thanks for reaching out. Your feedback means a lot to us! Our list shows us you are a valued subscriber already and our emails are being sent to you. Could you kindly take a quick peek in your spam folder and let us know if you still haven’t received them? Thank you so much!

  2. I tried inserting a “more” break in Category description but this does not work. Would it be possible to have your snippet “hide” somehow extra text and make it viewable when clicked on?

  3. Hi how can this be done to the post description?

  4. After 2 hrs search – you are my hero!!!

    1. Shahzad Saeed May 30, 2019 at 11:56 am

      Glad it helped!

  5. Thank you for this. I wonder if it is possible to do the same for the title of the post in the admin panel?

    1. Hi Torbjorn ill try and post a snippet soon that will do just that.

  6. Thanks Kevin,
    I am a bit of a WordPress noob and was wondering how the snippet could be altered to truncate custom taxonomy descriptions?

    1. Sorry Kevin, just figured that out. Silly me.

      1. No problem Mike glad to hear you got things working.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!