<?php /** * Shorten text **/ function shortenText($text, $max = 50, $append = '…') { if (strlen($text) <= $max) return $text; $return = substr($text, 0, $max); if (strpos($text, ' ') === false) return $return . $append; return strip_tags( preg_replace('/\w+$/', '', $return) . $append ); } /** * Example usage: * echo shortenText( apply_filters('the_content',get_the_excerpt()), 100 ); **/