Created
October 29, 2012 10:00
-
-
Save jibone/3972702 to your computer and use it in GitHub Desktop.
Get first paragraph from post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo get_the_content_first_paragraph(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment