Post

Removing Images in a WordPress Post (Revisited)

A while back I wrote a semi-popular post on removing images from a WordPress post – today I am revisiting it. The original solution used the_content() and the output buffer to remove the images out of the post. Now that I have used WordPress a bit longer and candidly had to use the solution again and thought “what was I thinking” I thought I would share the cleaner solution:

1
<?php echo preg_replace('/&lt;img[^&gt;]+./','',get_the_content()); ?>
This post is licensed under CC BY 4.0 by the author.