Skip to content

Instantly share code, notes, and snippets.

@thedavedavies
Forked from banago/get-fisrt-paragraph.php
Last active October 13, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedavedavies/af975d5838fb73d621bc3ac15b36a252 to your computer and use it in GitHub Desktop.
Save thedavedavies/af975d5838fb73d621bc3ac15b36a252 to your computer and use it in GitHub Desktop.
Get first paragraph from a WordPress post.
<?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>');
echo '<p>' . $str . '</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment