2015-05-18 66 views
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」。

任何想法?

回答

0

只需使用相同的CSS引導程序用於.img-responsive併爲您的圖像庫創建選擇器並將該CSS應用於您的新選擇器