JustinCann
7/7/2016 - 8:00 AM

Wordpress - Short First Sentence of Post

Wordpress - Short First Sentence of Post

<?php
	
function show_first_sentence_of_post()
{
	
	$content = get_the_content();
			
    $content = html_entity_decode(strip_tags(str_replace("&nbsp;", '',$content)));
    $pos = strpos($content, '.');
       
    if($pos === false) {
        return $content;
    }
    else {
		
		if ($pos > 250) {
			$pos = 250;
			$ellipsis = "...";
		}
		
		$first_sentence = substr($content, 0, $pos + 1); 
		
        return  $first_sentence.$ellipsis;
    }
} /* end show_first_sentence_of_post function */