Ive got the following function wrapping all iframe's in a div class="video-container"
I want to target only iframes that contain a src beginning with src="www.youtube
Is there a way to modify this function do be more specific?
Thanks in advance.
function div_wrapper($content) {
// match any iframes
$pattern = '~<iframe.*</iframe>~';
preg_match_all($pattern, $content, $matches);
foreach ($matches[0] as $match) {
// wrap matched iframe with div
$wrappedframe = '<div class="video-container">' . $match . '</div>';
//replace original iframe with new in content
$content = str_replace($match, $wrappedframe, $content);
}
return $content;
}
add_filter('the_content', 'div_wrapper');