-
-
Save brettkelly/7017281 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* Get first paragraph from a WordPress post. Use inside the Loop. | |
* | |
* @return string | |
*/ | |
function get_first_paragraph(){ | |
global $post; | |
$str = wpautop( get_the_content() ); | |
$firstP = strpos( $str, '</p>' ); | |
$secondP = strpos( $str, '</p>', ($firstP + 1) | |
$p1 = substr( $str, 0, $firstP + 4 ); | |
$p2 = substr( $str, ($firstP + 4), $secondP); | |
$p1 = strip_tags($p1, '<a><strong><em>'); | |
$p2 = strip_tags($p2, '<a><strong><em>'); | |
return '<p>'.$p1.'</p><p>'.$p2.'</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment