WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As the title says, I want to automatically remove a specific image in all posts where it's used when I remove the image from the media library. Because at the moment, if I remove an image from the media library the "empty image" stays in the post(so all the html code) but nothing is being displayed of course. Is there any way/plugin?

Thanks in advance.

share|improve this question

I was not able to find plugin for that and I think there might be a problem to find one.

Problem is not easy to solve because as I just checked in WordPress database reference (http://codex.wordpress.org/images/9/9e/WP3.0-ERD.png) there is not special container for images in post content.

If I understand correct your plugin needs to:

  • hook to action when media is removed,
  • search through all your posts looking for image url,
  • find in post content image url and html 'a' tag for it,
  • remove 'a' tag with image tag

It is not soo hard to write it but performence of plugin depends on how many posts you have on your blog.

share|improve this answer
That's what I thought, I'll have to do it the hard way with regex :) I'll have to code it tomorrow then and post my results here. If anybody got any other suggestions that would be great. – Stephan S. Dec 17 '12 at 23:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.