How to automatically wrap image in a div

How to automatically wrap image in a div

Uploaded images (images added through media upload box) can be easily wrapped in a div by applying a filter to the image_send_to_editor function, like this:

function wcr_wrap_image($html, $id, $caption, $title, $align, $url, $size, $alt) {
    return '<div class="wrap_class">' . $html . '</div>';
}

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

The code above will generate this output:


<div class="wrap_class">
    <!-- your image here -->
</div>
Leave a Reply

Get our Wordpress
freebies to your inbox