Created
March 9, 2017 16:42
-
-
Save munts/8bcae10d8e5fa654f1259ed11c4d4d34 to your computer and use it in GitHub Desktop.
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
//Trm excerpt | |
function berglund_trim_excerpt($length) { | |
global $post; | |
$explicit_excerpt = $post->post_excerpt; | |
if ('' == $explicit_excerpt) { | |
$text = get_the_content(''); | |
$text = apply_filters('the_content', $text); | |
$text = str_replace(']]>', ']]>', $text); | |
} else { | |
$text = apply_filters('the_content', $explicit_excerpt); | |
} | |
$text = strip_shortcodes($text); // optional | |
$text = strip_tags($text); | |
$excerpt_length = $length; | |
$words = explode(' ', $text, $excerpt_length + 1); | |
if (count($words) > $excerpt_length) { | |
array_pop($words); | |
array_push($words, '...'); | |
$text = implode(' ', $words); | |
$text = apply_filters('the_excerpt', $text); | |
} | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment