Here’s how you can do that. Add the following to your theme’s functions.php
template file:
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'my_custom_excerpt');
function my_custom_excerpt($text) { // Fakes an excerpt if needed
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 55;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '[<a href="'. get_permalink() . '">...</a>]');
$text = implode(' ', $words);
}
}
return $text;
}
All I’ve done is remove the wp_trim_excerpt
function from the get_the_excerpt
callback, and then modified wp_trim_excerpt
into what I’ve called “my_custom_excerpt
“, just adding the link to the post around the ellipses.
Roy
(@gangleri)
Wow, Filosofo on his way 🙂
Personally I’d just change the_excerpt
by the_content
again and use an excerpt plugin (I like Excerpt Editor) which replaces the [...]
by anything your like, such as “continue reading posttitle”, perhaps even a linked [...]
.
I’m spoiled with choice…
Thanks for the solutions.
La M
(@lady_moocher)
Hi filosofo
I’d like to implement your code above in my kubrick theme. I had a look at the functions file, but I don’t see anything about excerpts in it (v2.7).
This thread is 9 months old so maybe things have changed by now.
So does it matter where in the file this code is put?
Curious to know where this […] is actually being generated from.
Thanks