4

I want to remove "thumbnail", "medium_large" and "original" sizes. I wrote this in functions.php

if (function_exists('add_theme_support')) {
  // Add Menu Support
  add_theme_support('menus');

  // Add Thumbnail Theme Support
  add_theme_support('post-thumbnails');
  //add_image_size('large', 700, '', true); // Large Thumbnail
  //add_image_size('medium', 250, '', true); // Medium Thumbnail
  //add_image_size('small', 120, '', true); // Small Thumbnail
  //add_image_size('custom-size', 700, 200, true); // Custom
  remove_image_size('medium_large');
  remove_image_size('thumbnail');
  remove_image_size('original');

  // Enables post and comment RSS feed links to head
  add_theme_support('automatic-feed-links');
}

I added some context and the commented add_image_size functions to show that this code is accessible and that previously those functions worked, creating additional thumbnail sizes.

But now, this exact code is not removing the desired image sizes. When I upload an image, the system creates exactly 5 images:

  • Original: 1920x1080
  • medium_large: 768x432
  • large: 570x321 (because redefined in Options > Media to 570x570)
  • medium: 350x197 (because redefined in Options > Media to 350x350)
  • thumbnail: 150x150

This is absolutely coherent with the fact that all remove_image_size answer with false, so something isn't working.

Why remove_image_size is not working? Thank you.

PS: I'm using Wordpress 4.7.3

1 Answer 1

3

I don't think it works that way. I think remove_image_size only affects image sizes created by plugins or themes, not the core ones in WordPress (could be wrong). If you want to use it to remove "custom" sizes you added, you will still need to hook it into an action to actually run it:

function remove_image_sizes() {
if ( function_exists( 'add_image_size' ) ) { 
    remove_image_size( 'custom-image-size1');
    remove_image_size( 'custom-image-size2');
 }
}
add_action('after_setup_theme', 'remove_image_sizes');

If you want want to remove core sizes, you'll need to do something different.

function paulund_remove_default_image_sizes( $sizes) {
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);

    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'paulund_remove_default_image_sizes');

You can read about options in more detail here: https://andorwp.com/add-remove-change-and-regenerate-image-sizes-in-wordpress/

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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