How to add automatic class in image for wordpress post

后端 未结 12 1503
时光说笑
时光说笑 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:38

    I think you don't require to add class to make image responsive. just remove height width from featured image, image will become responsive definitely.

    There is code put in your function.php to remove height width

    add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 );
    
    function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
        $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
        return $html;
    } 
    

提交回复
热议问题