Cannot get add_image_size to work

I am creating a WordPress theme and am trying to create different images of different sizes for the images that the user uploads to the "Advanced custom fields" field. However, when I use the code below, use the Regenerate Thumbnails plugin to create new image sizes that do not seem to be affected.

I feel that there is something very simple that I am missing, because of everything I read, this should work. The code below is a shortened version of the actual function, there are several smaller image sizes in the one I use.

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 above code fits into my themes functions.php.

+4
source share
2

, :

// Enable post thumbnails
add_theme_support('post-thumbnails');

// Custom image sizes
if ( function_exists( 'add_image_size' ) ) { 
	add_image_size( 'carousel-mobile', 640, 400, true );
	add_image_size( 'carousel-tablet', 980, 602, true );
	add_image_size( 'carousel-desk', 1400, 580, true );
	add_image_size( 'feed-thumb', 300, 185, true );
	add_image_size( 'article-featured', 640, 300, true );
	add_image_size( 'list-thumb', 382, 204, true );
}
Hide result

ACF , ,

<?php $image = get_field('image'); ?>

<img src="<?php echo $image['sizes']['list-thumb']; ?>" alt="">  
Hide result
0

, after_theme_setup hook init. .

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' );
0

Source: https://habr.com/ru/post/1657679/


All Articles