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

preg_replace() 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.


Über mich

Ich bin gelernter Mediengestalter, studierter Druck- und Medientechniker und leidenschaftlicher Tüftler und Bastler.

Beruflich beschäftige ich mich mit der digitalen Transformation von Unternehmen, sowie der Automatisierung von Unternehmensprozessen, in der Druck- und Medienbranche. Mehr dazu findet sich im Lebenslauf.

Privat interessieren mich Kaffee(maschinen), Themen rund um Webentwicklung, das Internet im Allgemeinen und Speziellen und vieles, vieles mehr.

Ich freue mich auf Feedback per E-Mail unter kontakt@flomei.de, einen Euro für die Kaffeekasse oder etwas von meiner Amazon Wunschliste.