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:
Clean solution. Thanks for your work
yuo thats pretty good
Pingback: Removing Images from a WordPress Post | Chris Schuld's Blog
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.
Commentators: a noteworthy endorsement. I’ve worked with Chris for 7+ years…great mind…good soul…remarkable code! Hire him ASAP. Donald Teel.
Pingback: Remove images from Wordpress loop « labs.steveottenad.com
Hi Chris,
Thanks for a good solution I’ve been searching for! I’m having an issue that others have posted about; the image is removed, however all of my formatting is also removed, so I am left with text with no paragraph breaks and things like that. I’m not a very good coder, so I was wondering if you may have a fix for that issue? Thanks so much!
Hi again. The problem is with using get_the_content which strips out formatting. I found a hack around it here, which worked great.
http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/
great solution, but is there any way to remove IMG and other EMBED tag as well? Not a coder, hope u guys can help out. thanks!