Having the ability to truncate a string of text and add ‘…’ to the end without breaking or cutting off in the middle of a word is quite a common requirement, here’s how to do it
There is a useful post on http://stackoverflow.com/a/1104329 which explains one method of achieving this. In my example below I am retrieving the string from an Advanced Custom Field in a CPT loop hooked up to a Flexslider
<div class="flexslider"> <ul class="slides"> <?php $args = array ( 'post_type' => array( 'clients' ), 'order' => 'DESC', ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $str = get_field('testimonial'); $str = wordwrap($str, 185); $str = explode("\n", $str); $str = $str[0] . '...'; ?> <li style="padding: 0px; text-align: center;"> <span class="testimonial-content" style="font-style: italic; font-weight: light; line-height: 25px; font-size: 20px;">“<?php echo $str; ?> <a href="/read-the-reviews/">Read More</a></span> </li> <?php } } wp_reset_postdata(); ?> </ul> </div>