I noticed that most examples of add_image_size() is done via the after_setup_theme hook.
Which means, for it to register, one has to switch theme and reactivate the theme.
Which is not ideal for me as the website I am working on is already in Production. We can't have the monitoring software notifying the higher ups and ringing alarm that the website went ugly every time we push a new custom image size.
So I thought I can register the new custom image sizes using a plugin. So instead of using the after_setup_theme we will use the register_activation_hook of the plugin, like so:
if (!function_exists('xxxx_add_image_sizes')) {
function xxxx_add_image_sizes() {
require_once(ABSPATH . 'wp-admin' . '/includes/image.php');
require_once(ABSPATH . 'wp-admin' . '/includes/file.php');
require_once(ABSPATH . 'wp-admin' . '/includes/media.php');
add_image_size( 'jsa-hero-banner', 1400, ( 1400 / 2 ), true );
// bootstrap xxl
add_image_size( 'jsa-bs-sm-ratio-4-3', 576, 576 * ( 3 / 4 ), true );
// bootstrap sm
add_image_size( 'jsa-bs-md-ratio-4-3', 768, 768 * ( 3 / 4 ), true );
// bootstrap md
add_image_size( 'jsa-bs-lg-ratio-4-3', 992, 992 * ( 3 / 4 ), true );
// bootstrap lg
add_image_size( 'jsa-small-thumbnail', 300, 300 * ( 3 / 4 ), true );
// used for image gallery component, ettc.
add_image_size( 'gfcq-50-50-image', 519, 675 );
}
}
if (!function_exists('xxxx_activate')) {
function xxxx_activate() {
xxxx_add_image_sizes();
}
}
register_activation_hook( FILE, 'xxxx_activate' );
I can confirm that the hook is getting called and even the xxxx_add_image_sizes() is getting called, but even so, the custom image size is NOT getting registered.
Any thoughts? Is it not possible to register custom image size via plugins?
Regards,