I'm getting image fields wrapped in tags and would like to remove the surrounding divs, but only if they are of class "mceTemp". Anyone know of an efficient way to do this?

Also, should those Divs even be there?

  • So I wrote a recursive function which sort of works:
    – codecowboy
    Oct 14 '10 at 9:01
  • function recursive_replace($string) { preg_match('/<div class\=[\"]mceTemp[\"]\>(.*?)<\/div>/si',$string,$matches); if($matches) { $string = preg_replace('/<div class\=[\"]mceTemp[\"]\>(.*?)<\/div>/si','$1',$string); recursive_replace($string); } else { return $string; } }
    – codecowboy
    Oct 14 '10 at 9:02
  • feel free to improve on it!
    – codecowboy
    Oct 14 '10 at 9:02
  • Normally you should not run over those as tinymce removes them on it's own.
    – hakre
    Oct 14 '10 at 21:00
  • I'm wondering if the plugin custom field templates is the culprit. Someone installed this and made a mess of it.
    – codecowboy
    Oct 14 '10 at 21:56

I agree with hakre - something funky is going on elsewhere, those shouldnt be appearing.

As a sidenote, you could use the jQuery unwrap() function to remove those divs.

jQuery('div.mceTemp img').unwrap();


  • cool. That is good to know ;-)
    – codecowboy
    Oct 19 '10 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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