WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used custom post type, where 'thumbnail', 'medium' and 'large' sized not required. I need to disable this sizes and create function or plugin, where i can set, which image size is required for each custom post type.

My first step is hooking of get_intermediate_image_sizes function from wp-includes/media.php. I have added this code to functions.php but it not working :(

add_filter('get_intermediate_image_sizes', 'get_intermediate_image_sizes_fixed');
function get_intermediate_image_sizes_fixed() {
    global $_wp_additional_image_sizes;
    //$image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
    $image_sizes = array();
    if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
        $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
return apply_filters( 'intermediate_image_sizes', $image_sizes );

UPD: Editing this line in media.php is working. Default types after changes not generating.

$image_sizes = array('thumbnail', 'medium', 'large');

But how to make work my hook?

share|improve this question
would like an answer to this too – drtanz Dec 11 '11 at 21:34
That's not how you use that filter. To clear default sizes you just need to add it with a very low priority and return an empty array. However that won't solve your problem, because that will affect all post types. I don't think there's a way to do what you want in the current WP version. Try requesting WP devs to add the $attachment_id argument to the filter inside this function. That way you can check the post type inside your hook – onetrickpony Dec 11 '11 at 23:57
My step is only experiment but not full solution. How i can use filter correctly? P.S. Thank you for link.. – Bohdan Hdal Dec 12 '11 at 0:00
Any changes to WP that makes it possible now? – Drivingralle May 13 at 7:41
No changes. Still the same problem. – Bohdan Hdal May 31 at 15:56
up vote 5 down vote accepted

I think the only solution you have at the moment is to disable all intermediate image sizes:

add_filter( 'intermediate_image_sizes', '__return_empty_array', 99 );

And then manually generate them, depending on the post type, by hooking into 'wp_generate_attachment_metadata', where you do have access to the attachment id (and therefore to it's parent post):

function do_your_stuff( $data, $attachment_id ) {
  // generate intermediate images

  return $data;

add_filter( 'wp_generate_attachment_metadata', 'do_your_stuff', 10, 2 );
share|improve this answer
What are the 10 & 2 parameters you pass into the last add_filter? – Luke Feb 2 '12 at 4:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.