Skip to content

Instantly share code, notes, and snippets.

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 petersplugins/3d2caeeea51bb7d06d5512ce631e00f1 to your computer and use it in GitHub Desktop.
Save petersplugins/3d2caeeea51bb7d06d5512ce631e00f1 to your computer and use it in GitHub Desktop.
<?php
// This code snippet uses the first paragraph of an article as excerpt
// use an anonymous function to filter the excerpt
// this changes the behavior of the function the_excerpt() to use the first paragraph
add_filter( 'wp_trim_excerpt', function( $text, $raw_excerpt ) {
$content = apply_filters( 'the_content', get_the_content() );
return substr( $content, 0, strpos( $content, '</p>' ) + 4 );
} ), 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment