WordPress: Removing full size images from excerpt – the clean way

Refering to my post a few days ago, I come back to removing images from excerpts.

The way I described in the last post was to simply hide the images on the frontpage. This works fine if you want only fullsize images to be not displayed.

Taking it one step further is to remove the images from the excerpt.

The easiest way to do this is by using

_pregreplace() and a regular expression which searches for img-tags.

$content = preg_replace("/<img[^>]+\>/i", "", $content);

This works fine if your excerpt is in $content. It simply removes all img-tags from $content.

Besides to simply removing all the images from the excerpt you could also replace them with a placeholder text like „Images are shown in full post“ or whatever you like.

Just enter the content you want to be displayed between the second pair of quotation marks.