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:
<?php echo preg_replace('/<img[^>]+./','',get_the_content()); ?>
Clean solution. Thanks for your work
yuo thats pretty good
How can I have wordpress to generate html tags, like . Using this method I get “plain” text in the post.
where i must add the code?
I can’t see the code above, just the dots. Any chance of showing the code to do the updated version?
Cozzy:
Fixed, thanks!
im just curious, this strips EVERYTHING and leaves behind and links to other content in the post, any way of working around this? im trying to use Fast Tube plugin, and it just leaves the link, but doesnt publish the video?
great post chris, help me a lot
The regular expression is off.
/<img[^>]+./ Will get rid of everything after an opening of an image tacg up until it hits something other than & or g or t or ;. The final dot is also useless and potentially dangerous since you can’t presume it’s a space.
The more appropriate regex would be:
/<img.*?(>)/
You should also make it case-independent and test it with multi-line image tags.
Appreciate your efforts but you may want to pick up a book on regular expressions.
Your blog converted my lt & gt into actual brackets. Comments should be converting ampersand characters into the appropriate HTML entity.