Hello, I’m trying make a short plugin to replace all <img> tags in the_content with <href><img> tags. Is this possible with preg_replace?
More specifically, i’d like to place every:
<a href="anyfile"><img src="anyfile"></a>
I’m not experienced with regex, but here is what i have so far, which isn’t working:
define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);
$pattern = '/<a(.*?)img(.*?)src="(.*?).(bmp|gif|jpeg|jpg|png)"(.*?)>/i';
$replacement = '<a$1$2href="$3.$4" rel=\'lightbox[imagegroup]\'$5><a img src=$3.$4"></a>';
return preg_replace($pattern, $replacement, $string);
The overall goal is to have embedded images be clickable, so that they open in their original size using lightbox (or slimbox, etc.)
Thanks for any help or tips.