Remove URL from wordpress excerpt

If you have URLs showing up in your excerpt simply add the following somewhere in the top of your theme’s index.php file.

<?php
function RemoveURL($string)
{
  return preg_replace(‘/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i’, ”, $string);
}
add_filter(‘the_excerpt’, ‘RemoveURL’);
?>

This will remove 99% of the URLs in your excerpts.

One thought on “Remove URL from wordpress excerpt”

  1. Hi!

    After using your function all my excerpts (auto generated by the_excerpt function) point to homepage, they don’t have the proper link to each post. Any idea why this happen?

Leave a Reply

Your email address will not be published. Required fields are marked *


+ nine = 12

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>