The normal way to do this would be to use the_excerpt()
instead of the_content()
in your archive templates, then use this filter the change the number of words that appear in the excerpt:
function wpse_280633_excerpt_length() {
return 20;
}
add_filter( 'excerpt_length', 'wpse_280633_excerpt_length' );
If you want to stick with what you’ve got and not apply it to single post views, use a combination of is_main_query()
and is_singular()
to check if you’re in a list of posts or not:
function wpse_280633_break_text( $content ) {
if ( is_main_query() && ! is_singular() ) {
$length = 500;
if(strlen($content)<$length+10) return $content;//don't cut if too short
$break_pos = strpos($content, ' ', $length);//find next space after desired length
$visible = substr($content, 0, $break_pos);
$content = balanceTags($visible) . "<a href="".get_permalink()."">read more</a> ";
}
return $content;
}
add_filter( 'the_content', 'wpse_280633_break_text' );