Monday, October 1, 2012

Automatically wrap images in the_content with custom html

Adding this snippet to the functions.php of your wordpress theme will automatically wrap images in the_content with any custom HTML that you wish.
function filter_images($content){
    return preg_replace('/<img (.*) \/>\s*/iU', '<span class="className"><b><img \1 /></b></span>', $content);
}
add_filter('the_content', 'filter_images');

No comments:

Post a Comment