Image size filtering in Media uploader according to custom post type

Add following code in your themes functions.php file

function theme_set_default_image_size() {
global $post_type;
$custom_image_size="medium";   

if($post_type == 'news')
    $custom_image_size="news_image_size";
else if($post_type == 'product')
    $custom_image_size="product_image_size";
else if($post_type == 'service')
    $custom_image_size="service_image_size";

return $custom_image_size;
}
add_filter( 'pre_option_image_default_size', 'theme_set_default_image_size' );

Leave a Comment