添加类img-response对wordpress中所有附加的帖子图像

ter*_*tor 1 html css php wordpress

我想将class = img-reponsive&img-shadow添加到所有附加的帖子缩略图我使用下面的函数,它工作正常,但它删除了原始的thubmails类

function add_responsive_class($content){

        $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
        $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-responsive img-shadow');
        }

        $html = $document->saveHTML();
        return $html;   
}
Run Code Online (Sandbox Code Playgroud)

但我想合并我的类不只是覆盖它所以我使用jquery

 jQuery(function() {
jQuery(img).addClass('img-responsive img-shadow ');
});
Run Code Online (Sandbox Code Playgroud)

但它给出的错误jquery没有定义

请帮帮我

ter*_*tor 7

function add_image_responsive_class($content) {
   global $post;
   $pattern ="/<img(.*?)class=\"(.*?)\"(.*?)>/i";
   $replacement = '<img$1class="$2 img-responsive img-shadow"$3>';
   $content = preg_replace($pattern, $replacement, $content);
   return $content;
}
add_filter('the_content', 'add_image_responsive_class');
Run Code Online (Sandbox Code Playgroud)