Skip to content

Instantly share code, notes, and snippets.

@allan23
Created August 28, 2018 16:59
Show Gist options
  • Select an option

  • Save allan23/54a8a11f9089bbcb78437da4936fb940 to your computer and use it in GitHub Desktop.

Select an option

Save allan23/54a8a11f9089bbcb78437da4936fb940 to your computer and use it in GitHub Desktop.
<?php
/**
* Generate excerpt from returned content from ElasticPress.
*/
function ep_excerpt( $excerpt ) {
global $post;
if ( ! isset( $post->elasticsearch ) ) {
return $excerpt;
}
$excerpt_length = apply_filters( 'excerpt_length', 55 );
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
$excerpt = wp_trim_words( $post->post_content, $excerpt_length, $excerpt_more );
return wp_kses_post( $excerpt );
}
add_filter( 'the_excerpt', 'ep_excerpt', 99, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment