我有这样一个函数:
function add_responsive_class($content)
{
$content = mb_convert_encoding($content, \'HTML-ENTITIES\', "UTF-8");
if (!empty($content)) {
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML(utf8_decode($content));
$imgs = $document->getElementsByTagName(\'img\');
foreach ($imgs as $img) {
$img->setAttribute(\'class\', \'img-fluid\');
}
$html = $document->saveHTML();
return $html;
}
}
add_filter(\'the_content\', \'add_responsive_class\');
这增加了
img-fluid
所有图像,但它也会删除
align-left
, 如何修改上述函数以添加
img-fluid
要映像而不是删除其他类?
比如--><img class ="img-fluid align-left"