In regards to image attachments inserted into a post, I would like to wrap the img tag inside a div tag for specific design purpose.

Is there a way to do this automatically after attaching the image file, like through hooks/filters maybe?

Thanks in advanced!!

2 Answers
2

It’s the image_send_to_editor filter:

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" id="mydiv-'.$id.'">'.$html.'</div>';
  }
}

For existing images/posts you can try the regex in the function below

Leave a Reply

Your email address will not be published. Required fields are marked *