Skip to content

Instantly share code, notes, and snippets.

@michelmany
Created July 4, 2017 15:32
Show Gist options
  • Save michelmany/87f1f76736c4831bf6613577a5e508b6 to your computer and use it in GitHub Desktop.
Save michelmany/87f1f76736c4831bf6613577a5e508b6 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>');
return '<p>' . $str . '</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment