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

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?

share|improve this question
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
up vote 1 down vote accepted

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();


share|improve this answer
cool. That is good to know ;-) – codecowboy Oct 19 '10 at 10:31

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.