Article length in categories


Hey Boris,

Here is an example code snippet to add to your child theme functions.php:

add_filter( 'the_content', 'example_category_truncated_content' );

function example_category_truncated_content( $content ) {

  // Only truncate for category view.
 if ( is_category() ) {
    // Return truncated content and readmore.
   return '<p>' . wp_trim_words( $content, 40, '...' ) . '</p><p>' . beans_post_more_link() . '</p>';
  }

 return $content;

}

You will notice that there is a check in the function that check if we are view a category, you may change that you apply to other views too. You will also see that I added the Read More link after the turncated content, you may remove that if you don't want it 🙂

Have fun,


Write a reply

Login or register to write a reply, it's free!