WordPress Excerpt – How to remove the first link using functions.php

The way you are using the filter is wrong. Your function should accept the excerpt as an argument:

function custom_excerpt( $excerpt ) {

Then you don’t need to do the get_the_excerpt() call, as you already have the value you want to edit. Furthermore, if you are replacing each word, one by one, you could hurt other parts of the excerpt, so I’d advise you to remove the whole sentence in a single call of str_replace().