How To Remove the […] From Excerpts in WordPress

remove-excerpts-dots-from-wordpress

If you want to remove or customize the way excerpts are outputted you can apply a simple function to your child theme’s functions.php file. In most cases you’ll have a “recent posts” section on a website and instead of having […] at the end of excerpts you can switch to to “read more” hyperlinked to the post.

1. Open your theme’s functions.php file. Paste the following code.


function trim_excerpt($text)
{
return rtrim($text,'[...]');
}
add_filter('get_the_excerpt', 'trim_excerpt');


This snippet will completely remove [...] from the excerpt.


function trim_excerpt($text)
{
return str_replace(' [...]', '...', $text);
}
add_filter('get_the_excerpt', 'trim_excerpt');


This snippet will replace [...] with ...


function trim_excerpt($text)
{
return str_replace(' [...]', '' . ' read more...', $text);
}
add_filter('get_the_excerpt', 'trim_excerpt');


This snippet will replace [...] with a read more hyperlinked to your post in your loop/query.

In some cases you wouldn't want to globally alter the excerpt feature on the site.


function change_excerpt( $more ) {
        if(post_type_exists('services')){
           return '';
        }
     return '...';
}
add_filter('excerpt_more', 'change_excerpt');


This snippet will replace only the 'services' custom post type excerpt [..] with a blank space, but for every other posts and page it will return ...

FOLLOW US ON: