I'm creating a WordPress theme and am trying to create various different sized images for the images the user uploads into an Advanced Custom Fields image field. However when I use the code below then use the Regenerate Thumbnails plugin to create the new image sizes it doesn't appear to have any affect.
I get the feeling there's something very basic I'm missing as from everything I've read this should work. The code below is a cut down version of the actual function, there's a fair few more image sizes in the one I'm using.
function test_add_image_sizes() {
add_theme_support( 'post-thumbnails' );
// Images used on blog index & category pages for the first item and at the top of the blog post page itself
add_image_size( "main-image", 700, 680, true );
add_image_size( "main-image-350", 350, 450, true ); // For use on screens 350 pixels & below
add_image_size( "main-image-539", 539, 573, true ); // For use on screens 539 pixels & below
add_image_size( "main-image-659", 659, 570, true ); // For use on screens 659 pixels & below
add_image_size( "main-image-850", 850, 650, true ); // For use on screens 850 pixels & below
add_image_size( "main-image-1000", 1000, 650, true ); // For use on screens 1000 pixels & below
add_image_size( "main-image-1200", 1200, 680, true ); // For use on screens 1200 pixels & below
add_image_size( "main-image-1400", 1400, 680, true ); // For use on screens 1200 pixels & above
}
add_action( 'init', 'test_add_image_sizes' );
The code above is placed in my themes functions.php
file.
Hi use after_theme_setup
hook instead of init
. User regenerate thumbnail plugin for previously uploaded image size fixing.
function test_add_image_sizes() {
add_theme_support( 'post-thumbnails' );
// Images used on blog index & category pages for the first item and at the top of the blog post page itself
add_image_size( "main-image", 700, 680, true );
add_image_size( "main-image-350", 350, 450, true ); // For use on screens 350 pixels & below
add_image_size( "main-image-539", 539, 573, true ); // For use on screens 539 pixels & below
add_image_size( "main-image-659", 659, 570, true ); // For use on screens 659 pixels & below
add_image_size( "main-image-850", 850, 650, true ); // For use on screens 850 pixels & below
add_image_size( "main-image-1000", 1000, 650, true ); // For use on screens 1000 pixels & below
add_image_size( "main-image-1200", 1200, 680, true ); // For use on screens 1200 pixels & below
add_image_size( "main-image-1400", 1400, 680, true ); // For use on screens 1200 pixels & above
}
add_action( 'after_theme_setup', 'test_add_image_sizes' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With