I am using custom thumbs in my child theme for Storefront. I am using ACF repeater to add images to slider. To display custom sized images I used this code easily for woocommerce earlier:
$slider_image = get_sub_field('slider_image');
$custom_image = $slider_image['sizes']['home-slider'];
and here is how I registered custom image in functions:
function addthemesupport() {
remove_theme_support('post-thumbnails');
add_theme_support( 'post-thumbnails', array( 'post', 'page', 'product' ) );
//custom sizes:
add_image_size( 'home-slider', 400, 300, true );
add_image_size( 'home-featured', 200, 150, true );
}
add_action( 'after_setup_theme', 'addthemesupport', 11 );
However I get this error on front end:
Warning: Illegal string offset âsizesâ in â¦
Warning: Illegal string offset âhome-sliderâ in â¦
What is wrong with these? I took this part of the code:
custom_image = $slider_image[âsizesâ][âhome-sliderâ];
from ACF documentation
The solution was to set image field to Object rather than ‘Url’ like I had in ACF. This way the array of sizes is working fine.