• Here is my code:

         $content = apply_filters('the_content', get_the_content());
         $first_slice = html_entity_decode( wp_trim_words( htmlentities( $content ),100, '' ) );
         $second_slice = html_entity_decode( substr($content,strlen($first_slice),strlen($content)));
         echo '<div class="non-paywall">'. $first_slice .'</div>';
         echo '<div class="paywall">'. $second_slice .'</div>';

    Second slice is starting at wrong point and repeating few words that exist in first slice.

Viewing 1 replies (of 1 total)
  • PHP7

    $content = apply_filters('the_content', get_the_content());
    $slices = explode(" ", $content);
    $first_slice = implode(" ", array_splice($slices, 0, 100));
    $second_slice = implode(" ", array_splice($slices, 0));
    echo '<div class="non-paywall">'. $first_slice .'</div>';
    echo '<div class="paywall">'. $second_slice .'</div>';

    That work?

Viewing 1 replies (of 1 total)
  • The topic ‘Split the_content into two divs by X words?’ is closed to new replies.