Created
March 20, 2014 16:31
-
-
Save jchristopher/9667991 to your computer and use it in GitHub Desktop.
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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