WordPress has a build-in PHP function called “the_excerpt()” which calls the excerpt under your post’s settings (seen at the right side of a post’s editor). If that Excerpt field is empty, WordPress will call a trimmed down content of whatever is in the beginning of your editor. It might not be appealing especially if it’s only calling a limited amount of character or if it’s showing two paragraphs as one in an excerpt line.
One solutions is you can manually add or lessen the character output of the excerpt by adding a filer in your functions.php file called “wpdocs_custom_excerpt_length“. But this is advisable if you only want the excerpt to show a specific amount of characters.
If you would rather use the first full paragraph of your post’s content as the excerpt, it’s best to create your custom function for it.
To do that, go to your active theme’s functions.php file and add this PHP code at the bottom.
function the_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>';
}
Now that the function to get the first full paragraph is established, you can now get it to display as the excerpt in a loop.
Go to the template file where the loop exists, and just add your new function and use PHP’s “echo” to call it. See the sample code below on Line 7.
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title( '<h3>', '</h3>' );
the_post_thumbnail();
/* instead of using the_excerpt(), use the_first_paragraph() */
echo the_first_paragraph();
endwhile;
else:
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
?>