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

When I add an image to a post I want it to be in a div e.g. , and I want that to be done automatically, so I don’t have to do that in HTML editor.
I don’t want to use js to accomplish this and by the way I want to know how to automatically add custom classes to a image in a post. Cheers!

4 Answers

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,


function my_custom_class($class){
return $class;

Leave a Comment