Skip to content

Instantly share code, notes, and snippets.

@ivankravchenko
Created January 30, 2013 12:56
Show Gist options
  • Save ivankravchenko/4673100 to your computer and use it in GitHub Desktop.
Save ivankravchenko/4673100 to your computer and use it in GitHub Desktop.
<?php
function new_excerpt_more($more) {
global $post;
//return '<a class="read-more" href="'. get_permalink($post->ID) . '">' . $more . '</a>';
return '... <a class="read-more" href="'. get_permalink($post->ID) . '">&gt;</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
function improved_trim_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]&gt;', $text);
$text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
global $saveimgs;
if ($saveimgs) {
$text = strip_tags($text, '<p>');
} else {
$text = strip_tags($text, '<p>');
}
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
$text = implode(' ', $words);
$text .= apply_filters('excerpt_more', '[...]');
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment