Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

wrap existing images with extra tags WordPress



I'm coding a new theme for an existing site and there is a requirement to have post images wit a CSS3 page curl drop shadow like so

this requires to wrap the images with 2 tags. there is a function that works for new images being inserted:

/* wrap images with span */

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

function wrap_my_div($html, $id, $caption, $title, $align, $url, $size, $alt){
return '<b class="curl"><b>'.$html.'

but I need to apply this to existing posts if possible. So is there a way to do that?


Answers (1)


Luis Abarca answers:

Yep, just check the css clases, you mean the images in the post content right ?

[[LINK href=""]][[/LINK]]

You can also flter the_content and add the code for each images

function filter_images($content){
return preg_replace('/<img (.*) \/>\s*/iU', '<b class="curl"><img \1 /></b>', $content);

add_filter('the_content', 'filter_images');

Im runing this code here [[LINK href=""]][[/LINK]], notice the code in the image

or with jQuery :

$('article img').wrap('<b class="curl"></b>');

paul de wouters comments:

thanks that did the trick!