Khi sử dụng wordpress bạn cần thêm 1 số class cho mọi hình mình tải lên trang wordpress sau đâu là đoạn code giúp bạn làm điều đó
// thêm class cho cai hinh
function wpc_add_image_responsive_class( $html ){
$classes = ‘img-responsive‘; // separated by spaces, e.g. ‘img image-link’
// check if there are already classes assigned to the anchor
if ( preg_match(‘/<img.*? class=”/’, $html) ) {
$html = preg_replace(‘/(<img.*? class=” .*?)(“.*?\=””>)/’, ‘$1 ‘ . $classes . ‘ $2’, $html);
} else {
$html = preg_replace(‘/(<img.*?)(\>)/’, ‘$1 class=”‘ . $classes . ‘” $2’, $html);
}
// remove dimensions from images,, does not need it!
$html = preg_replace( ‘/(width|height)=\”\d*\”\s/’, “”, $html );
return $html;
}
add_filter( ‘the_content’,’wpc_add_image_responsive_class’,10 );
add_filter( ‘post_thumbnail_html’, ‘wpc_add_image_responsive_class’, 10 );
trong đoạn code trên ta thêm class img-responsive vào mọi hình khi up lên trong bài viết bạn có thể thay bằng mọi class bạn muốn