Skip to content

Instantly share code, notes, and snippets.

@munts
Created March 9, 2017 16:42
Show Gist options
  • Save munts/8bcae10d8e5fa654f1259ed11c4d4d34 to your computer and use it in GitHub Desktop.
Save munts/8bcae10d8e5fa654f1259ed11c4d4d34 to your computer and use it in GitHub Desktop.
//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