@protohominid Thank you for your topic. Note there are a lot of factors that can influence what image size is served to visitors (device, screen size, etc). The editor will generate various thumbnail sizes for all your images and choose the most appropriate ones. The extra image sizes are needed to adhere to the Web Story format’s requirements for poster images and publisher logos. Unfortunately, WordPress does not provide any functionality for plugin developers to add image sizes only when needed and avoid creating unnecessary image sizes.
I’m not asking for the plugin to only add the sizes when needed; I’m asking if I can disable the creation of new sizes by the plugin going forward.
WordPress has the “remove_image_size()” function, but I can’t get it to work on the Web Stories registered sizes. I tried it with the ‘init’ and ‘after_setup_theme’ action hooks.
Why doesn’t the remove_image_size() function work in this case?
This is my code:
add_action( 'init', 'nm_remove_extra_images' );
function nm_remove_extra_images() {
remove_image_size( 'web-stories-poster-portrait' );
remove_image_size( 'web-stories-poster-landscape' );
remove_image_size( 'web-stories-poster-square' );
remove_image_size( 'web-stories-publisher-logo' );
remove_image_size( 'web-stories-thumbnail' );
}
-
This reply was modified 5 years, 5 months ago by
protohominid.
The plugin’s image sizes are registered on init with priority 10 (the default). If you want to remove them, use a higher number to call your function, e.g. add_action( 'init', 'nm_remove_extra_images', 20 );
Doh! I forgot to try adding the priority argument. That seems to have worked. Thanks Pascal!