-
-
Save gagimilicevic/1d0f3e0ff922705bbe84b510caa54995 to your computer and use it in GitHub Desktop.
Get first paragraph from a WordPress 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
<?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() ); | |
$str = substr( $str, 0, strpos( $str, '</p>' ) + 4 ); | |
$str = strip_tags($str, '<a><strong><em>'); | |
return '<p>' . $str . '</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment