How to wrap every image in a post with a div?

By default images already have unique class’s but this depends on your theme. Use firebug and hover over the images and you should see stuff like class="aligncenter size-full wp-image-1525".

If you want to change the class or id or alter any attributes of the image you can use the get_image_tag filter. For example,

add_filter('get_image_tag_class','my_custom_class');

function my_custom_class($class){
$class="my_custom_name";
return $class;
}

Leave a Comment