Divide Post content into separate divs for every 500 characters (or any other character counts)

get_the_content() return what’s in the editor, but wpautop filters and such are attached to the_content (which you don’t need inside your split function – just apply it later manually with

apply_filters( 'the_content', $output );

at the end.

You should as well use strip_shortcodes( get_the_content() ); before splitting it up:

$output = get_the_content();
$output = wp_trim_words( $output, 500 );

You’ll need to loop through it as long as you got content and array_push() to your $output = array();.

Leave a Comment