使用Wordpress过滤器。将此添加到您的函数中。php:
function div_wrapper($content) {
// match any iframes
$pattern = \'~<iframe.*</iframe>|<embed.*</embed>~\';
preg_match_all($pattern, $content, $matches);
foreach ($matches[0] as $match) {
// wrap matched iframe with div
$wrappedframe = \'<div>\' . $match . \'</div>\';
//replace original iframe with new in content
$content = str_replace($match, $wrappedframe, $content);
}
return $content;
}
add_filter(\'the_content\', \'div_wrapper\');