Skip to content

Instantly share code, notes, and snippets.

@NicolasPio
Forked from banago/get-fisrt-paragraph.php
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save NicolasPio/fbcbaae1b1a1b544c7ed to your computer and use it in GitHub Desktop.

Select an option

Save NicolasPio/fbcbaae1b1a1b544c7ed to your computer and use it in GitHub Desktop.
<?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 $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment