Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use SearchWP's Term Highlight extension to grab an excerpt from anywhere it can (e.g. if no matches are in the actual excerpt, expand the search to string-based Custom Fields)
<?php
/* SearchWP Term Highlight offers an alternative to the_excerpt()
If you're looking to generate any sort of excerpt based on one of the following:
- the actual excerpt
- the generated excerpt from the post content
- the post content itself
- string-based custom field values
this function is for you. It will try to find one of the above (in that order)
and output something with at least one search term in it (if possible)
*/
// echo the excerpt (designed to be used IN PLACE OF the_excerpt
if( function_exists( 'searchwp_term_highlight_the_excerpt_global' ) ) {
searchwp_term_highlight_the_excerpt_global();
}
// return the excerpt (designed to be used IN PLACE OF get_the_excerpt
if( function_exists( 'searchwp_term_highlight_get_the_excerpt_global' ) ) {
$excerpt = searchwp_term_highlight_get_the_excerpt_global();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment