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

Question

I’ve just imported a blog into WordPress and all of the content begins with:

<a href="itunes.com">Listen on iTunes</a>

followed by the paragraph content, so all excerpts appear with “Listen on iTunes content excerpt…”

I’ve tried a few custom functions found here, but none seem to do the trick. What’s the best way to remove the Listen on iTunes text without having to move the iTunes link?

For example, I tried this… with no luck…

    function custom_excerpt() {
    $text = get_the_excerpt(); //Assigns the excerpt to $text
    $text = str_replace("Listen","", $text); // replacing the word with empty string
    $text = str_replace("on","", $text);
    $text = str_replace("iTunes","", $text);
    return $text;
}
add_filter('the_excerpt', 'custom_excerpt');

Thanks in advance!

0
Dave 4 weeks 2021-08-26T11:29:53-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse