How to get ... (3 dots) at the end of the excerpt? I am using this function in my functions.php
function word_count($string, $limit) {
$words = explode(' ', $string);
return implode(' ', array_slice($words, 0, $limit));
}
And echoing like this in my content.php:
echo word_count(get_the_excerpt(), '20');
I want 3 dots at the end of the excerpt. Please help. Thank you.
If your excerpts are always longer than 20 words, you can use the following to append ellipsis any time while truncate it with your word_count
function
echo sprintf("%s…", word_count(get_the_excerpt(), 20));
If the excerpts might also be 20 words or shorter, you should also check for it's length
the_excerpt_max_words(20);
function the_excerpt_max_charlength($limit) {
$words = explode(' ', get_the_excerpt() );
//if excerpt has more than 20 words, truncate it and append ...
if( count($words) > 20 ){
return sprintf("%s…", implode(' ', array_slice($words, 0, $limit)) );
}
//otherwise just put it back together and return it
return implode(' ', $words);
}
WordPress's the_excerpt()
function does this by default (though I think it uses [...]
).
I prefer a simple answer. See http://codex.wordpress.org/Function_Reference/the_excerpt
function new_excerpt_more( $more ) {
return ''; // replace the normal [.....] with a empty string
}
add_filter('excerpt_more', 'new_excerpt_more');