This is a follow-up question to: Differentiating between P tags wrapping images and P tags wrapping text nodes in Wordpress?
I would like to modify the solution:
function my_content_filter($content) {
return preg_replace('|<p>(<img[^<]*)</p>|i', '<p class="foo">${1}</p>', $content);
}
add_filter('the_content', 'my_content_filter');`
So that it works for a <p>
with more than one <img>
element.
Try if this works for you.
function my_content_filter($content) {
return preg_replace('|<p>((<img[^>]*>)*)<\/p>|i', '<p class="foo">${1}</p>', $content);
}
add_filter('the_content', 'my_content_filter');`