I'd like to convert my wordpress post img tags in my post to div background images. I currently have a function setup to add a class to the parent paragraph tag. Any idea how to edit the preg replace to change the img tag to a div and set the style="background-image: url("{img_src}");" with the img src?
My current function is:
function give_attachments_class($content){
$classes = 'class="img_wrap"';
$firstH2 = 'class="first_h2"';
$img_match = preg_match("/(<p.*?)(.*?><img)/", $content, $img_array);
$youtube_match =preg_match("/(<p><span)+[ ]+(class=)+['\"]embed-youtube/", $content, $output_array);
if(!empty($img_match))
{
$content = preg_replace('/(<p.*?)(.*?><img)/', '$1 ' . $classes . '$2', $content);
}
if(!empty($youtube_match))
{
$content = preg_replace("/(<p><span)+[ ]+(class=)+['\"]embed-youtube/", "<p class=\"img_wrap\"><span class='embed-youtube", $content);
}
$content = preg_replace('/<div .*?class="(.*?video-container.*?)">(.*?)<\/div>/','<p class="img_wrap"><span class="embed-youtube">$2</span></p>',$content);
return $content;
}