I want to hide a few custom image sizes from the media uploader:
The following code (posted here) works only for the default image sizes:
function remove_image_sizes($sizes) {
unset($sizes['image-name']);
return $sizes;
}
add_filter('image_size_names_choose', 'remove_image_sizes');
Is there a similar solution to unset custom image sizes?
Using
unset
andintermediate_image_sizes_advanced
will work but only on images uploaded after the function is added. To change it for existing images you need to regenerate them using a plugin ( in essence deleting that image size) or just hide that option from being visible.Tested on 3.5.1
So this
x-la
size will still show for images before theunset
function was added.To remove this you can.
Hide it from the display using
image_size_names_choose
To clarify the filters:
intermediate_image_sizes_advanced
– effects the actual uploadimage_size_names_choose
– effects the visibility of the dropdown in the media boxAlso note:
It could be that a theme or plugin is already using the
image_size_names_choose
filter somewhere since it is very common when usingadd_image_size
for custom images. If that is the case you can still use a secondimage_size_names_choose
filter and set the$priority
to fire after the first one.To view how filters work: http://codex.wordpress.org/Function_Reference/add_filter