Last active
September 8, 2016 06:35
-
-
Save furenku/10194a84f90bc5b9d4a8f832d898a31e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function search_excerpt_highlight() { | |
| $excerpt = get_the_excerpt(); | |
| $keys = implode('|', explode(' ', get_search_query())); | |
| $excerpt = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight">\0</strong>', $excerpt); | |
| echo '<p>' . $excerpt . '</p>'; | |
| } | |
| function search_title_highlight() { | |
| $title = get_the_title(); | |
| $keys = implode('|', explode(' ', get_search_query())); | |
| $title = preg_replace('/(' . $keys .')/iu', '<strong class="search-highlight">\0</strong>', $title); | |
| echo $title; | |
| } |
This file contains hidden or 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
| .search-highlight { | |
| color: #fa0; | |
| } |
This file contains hidden or 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 echo apply_filters('the_title', search_title_highlight() ); ?> | |
| <?php echo apply_filters('the_excerpt', search_excerpt_highlight() ); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment