0

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>';
  }
}
1
0

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>';
  }
}

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.