Created
May 4, 2015 18:28
-
-
Save ovizii/e8b0e9879151772a586b to your computer and use it in GitHub Desktop.
Manipulate the excerpt
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
//removing and improving the excerpt | |
remove_filter('get_the_excerpt', 'wp_trim_excerpt'); | |
add_filter('get_the_excerpt', 'improved_trim_excerpt'); | |
/*improve the excerpt, keep HTML in there*/ | |
function improved_trim_excerpt($text) { | |
global $post; | |
if ( '' == $text ) { | |
$text = get_the_content(''); | |
$text = apply_filters('the_content', $text); | |
$text = str_replace(']]>', ']]>', $text); | |
/*uncomment below line to strip javascript*/ | |
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text); | |
/*add tags to include in excerpt below*/ | |
$text = strip_tags($text, '<p><a><img><ul><ol><li>[php][css][text][perl][shell]'); | |
$excerpt_length = 100; | |
$words = explode(' ', $text, $excerpt_length + 1); | |
if (count($words)> $excerpt_length) { | |
array_pop($words); | |
array_push($words, '[...]'); | |
$text = implode(' ', $words); | |
} | |
} | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment