Skip to content

Instantly share code, notes, and snippets.

@maugelves
Forked from banago/get-fisrt-paragraph.php
Last active October 28, 2016 19:15
Show Gist options
  • Save maugelves/15c3a77b948dc5d1f940d7187e7df53d to your computer and use it in GitHub Desktop.
Save maugelves/15c3a77b948dc5d1f940d7187e7df53d 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.
*
* @param $class string optional class name to include in the paragraph
* @return string
*/
function get_first_paragraph( $class = '' ){
global $post;
$str = wpautop( get_the_content() );
$str = substr( $str, 0, strpos( $str, '</p>' ) + 4 );
$str = strip_tags($str, '<a><strong><em>');
return '<p class="' . $class . '">' . $str . '</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment