Home Forums General Issues Warning: Illegal string offset 'sizes'


Warning: Illegal string offset 'sizes'

  • I am using custom thumbs in my child theme for Storefront. 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() {
      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 for the code:
    custom_image = $slider_image[‘sizes’][‘home-slider’];
    from ACF documentation

  • I solved it by setting image field to Object.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Warning: Illegal string offset 'sizes'’ is closed to new replies.