How to add automatic class in image for wordpress post

后端 未结 12 1496
时光说笑
时光说笑 2020-12-02 13:53

I want to make a responsive theme with Bootstrap 3. However, I need to automatically add the CSS class .img-responsive to every post image because I need the i

12条回答
  •  死守一世寂寞
    2020-12-02 14:23

    I had the same question, and adding this function to functions.php worked for me.

    function add_image_responsive_class($content) {
       global $post;
       $pattern ="//i";
       $replacement = '';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;
    }
    add_filter('the_content', 'add_image_responsive_class');
    

提交回复
热议问题