2013-09-21 72 views
1

我在wordpress中使用了「add_image_size」自定義圖片尺寸,並且工作正常。從媒體上傳器框中移除圖片尺寸

我試圖刪除默認的圖像大小與下面的代碼:

function filter_image_sizes($sizes) { 
    unset($sizes['thumbnail']); 
    unset($sizes['medium']); 
    unset($sizes['large']); 
    return $sizes; 
} 
add_filter('intermediate_image_sizes_advanced', 'filter_image_sizes'); 

但這些默認圖像尺寸仍然在媒體上傳彈出可見。

enter image description here

回答

5

你可以試試看

function my_custom_image_sizes($sizes) { 
    unset($sizes['thumbnail']); 
    unset($sizes['medium']); 
    unset($sizes['large']); 
    unset($sizes['full']); // removes full size if needed 

    // add your image sizes, i.e. 
    $myCustomImgsizes = array(
      "magazine-thumb" => __("Magazine"), 
      "slideshow-thumb" => __("Slideshow"), 
      "sidebar-thumb" => __("Sidebar") 
    ); 
    $newimgsizes = array_merge($sizes, $myCustomImgsizes); 
    return $newimgsizes; 
} 
add_filter('image_size_names_choose', 'my_custom_image_sizes'); 
1

在我localhost

使用unsetintermediate_image_sizes_advanced工作,但只上添加的功能後,上傳的圖片測試在3.5.1 。要更改現有圖像,您需要使用插件重新生成它們(實質上是刪除該圖像大小),或者只是隱藏該選項使其不可見。

// add custom image size 
function mytheme_95344() { 
     add_image_size('x-la',800,800, false); 
} 
add_action('after_setup_theme', 'mytheme_95344'); 

// remove it 
function remove_image_size_95344($sizes) { 
    unset($sizes['x-la']); 
    return $sizes; 
} 
add_filter('intermediate_image_sizes_advanced', 'remove_image_size_95344'); 

所以這x-la規模將仍然顯示的圖像添加了unset功能之前。

要刪除這個,你可以試試。

隱藏它使用image_size_names_choose

function remove_image_size_95344($possible_sizes) { 

unset($possible_sizes['x-la']); 
return $possible_sizes; 

} 
add_filter('image_size_names_choose', 'remove_image_size_95344'); 

回答顯示從https://wordpress.stackexchange.com/questions/95344/hide-custom-image-sizes-from-media-library#answer-95350