Quick Tip: replacing URLs in post excerpts


I generally find WordPress excerpts a little bit irritating. They ignore all formatting, including paragraphs, so you just end up with a block of text with no styling and sometimes little sense.

To make matters worse, if your content includes a URL you’ll end up with the whole thing displayed in the excerpt, no matter how long or nonsensical it looks. Luckily, this is easily remedied with a little code.

Drop the code below into your functions.php file and those URLs will be stripped out of the excerpt:

stuff we dig

FYI: yes, the above are affiliate links, so we do make a small amount of money if you follow them over and buy what they're selling. Thank you for helping pay our hosting costs!

Dave Kuhar

Dave ran Transmit Studio, a media creation lab in San José. He's built more websites with WordPress than he can remember. He's reluctantly moved back to Ohio and now works for Stanford University (remotely). He likes hearing himself talk and writing about himself in third person.


  1. Jonathan Weiner on December 29, 2020 at 5:53 am

    Just used this to fix raw ugly URLs displaying in my email newsletter. Thanks, Dave. VERY glad you made this simple but very valuable post. 🙂

    • Dave Kuhar on March 12, 2021 at 8:01 pm

      You’re welcome, glad you found it useful!

Leave a Comment