0
我正在使用Bootstrap 3 Wordpress主題。爲了讓我的圖片響應我加引導的IMG響應級將它們與下面的代碼在我的functions.php向WordPress的圖像添加引導img響應類失敗圖庫大拇指
<?php
function bootstrap_responsive_images($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','bootstrap_responsive_images',10);
add_filter('post_thumbnail_html', 'bootstrap_responsive_images', 10);
這工作得很好,都讓他們的階級=「IMG-響應「除了畫廊裏的大拇指。根據選擇的圖像大小,它們只有class =「attachment-thumbnail或attachment-medium」。
任何想法?