小编ter*_*tor的帖子

添加类img-response对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没有定义

请帮帮我

html css php wordpress

1
推荐指数
1
解决办法
3506
查看次数

标签 统计

css ×1

html ×1

php ×1

wordpress ×1