Skip to content

Instantly share code, notes, and snippets.

@jibone
Created October 29, 2012 10:00
Show Gist options
  • Save jibone/3972702 to your computer and use it in GitHub Desktop.
Save jibone/3972702 to your computer and use it in GitHub Desktop.
Get first paragraph from post.
if(!function_exists('get_the_content_first_paragraph')) :
function get_the_content_first_paragraph() {
$content = get_the_content();
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content_explode = explode("</p>", $content);
$c = 0; $p = count($content_explode); $return_data = "";
while($c < $p) {
$test = strip_tags($content_explode[$c]);
if($test != '') {
$return_data = $return_data . $content_explode[$c] . "</p>\n";
break;
} else {
$return_data = $return_data . $content_explode[$c] . "</p>\n";
} $c++;
}
return $return_data;
}
endif;
echo get_the_content_first_paragraph();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment