Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've tried the below code to wrap a post image with a div and it works. The problem I'm having is if the image has a caption. It screws up the the code that is generated when a caption is set for the image.

How can I modify this code to only be applied for an image with no caption?

if(is_admin()){

  add_filter('image_send_to_editor', 'wrap_my_div', 10, 8);

  function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){
    return '<div class="mydiv-'.$size.'" id="mydiv-'.$id.'">'.$html.'</div>';
  }
}
share|improve this question
    
This is the solution I started with:wordpress.stackexchange.com/questions/20998/… –  Jason Aug 28 '12 at 18:16
add comment

1 Answer

You could try with

if(is_admin()){

  add_filter('image_send_to_editor', 'wrap_my_div', 10, 8);

  function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt) {
     if( isset($caption) && $caption )
       return $html;
     else
       return '<div class="mydiv" id="mydiv-'.$id.'">'.$html.'</div>';
  }
}
share|improve this answer
add comment

Your Answer

 
discard

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.