
Today, here is an useful snippet to replace the ellipsis [...] from the excerpt with a permalink to the post.

Today, here is an useful snippet to replace the ellipsis [...] from the excerpt with a permalink to the post.
Paste the following code into your functions.php file. Once saved, the tip will be applied to your blog.
function replace_excerpt($content) {
return str_replace('[...]',
'... <div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
$content
);
}
add_filter('the_excerpt', 'replace_excerpt');
Thanks to CSS Tricks for the great snippet!
One Response
Hi there!
Why not to use the ‘excerpt_more’ filter (see the ‘wp_trim_excerpt’ function, default filter on ‘the_excerpt’)? It’s actually here to override that default ellipsis and will be passed to the wp_trim_words function as $more parameter.
With that method, you’ll not need to do a str_replace on your entire excerpt.
Lionel
Trackbacks: