Support

Account

Home Forums General Issues Illegal string offset \'url\' issue

Solving

Illegal string offset \'url\' issue

  • function mbgc_gallery_shortcode( $atts ) {
    
        $attributes = shortcode_atts(
            array(
                'id' => null
        ), $atts );
    
        // $attributes['id'] is now the passed-in ID
    
        $html_out = '';
    
        if( have_rows('mbgc_gallery', $attributes['id']) ):
    
            $html_out .= '<div class="mbgc-gallery owl-carousel owl-theme">';
    
            while( have_rows('mbgc_gallery', $attributes['id']) ): the_row();
    
            // vars
            $image = get_sub_field('mbgc_image');
            $caption = get_sub_field('mbgc_caption');
            $title = get_sub_field('mbgc_title');
            $sub_title = get_sub_field('mbgc_sub_title');
    
            if ( $image ) :
                $html_out .= '<div class="mbgc-gallery-item">';
    
                if ( $caption ) :
                    $html_out .= '<div class="mbgc-slide-caption">';
                        $html_out .= '<h4>' . $caption . '</h4>';
                        $html_out .= '<div class="mbgc-slide-titles">';
                            $html_out .= '<h6>' . $title . '</h6>';
                            $html_out .= '<h6>' . $sub_title . '</h6>';
                        $html_out .= '</div>';
                    $html_out .= '</div>';
                endif;
    
                $html_out .= '<div class="mbgc-slide">';
                    $html_out .= '<img src="' . $image['url'] . '" alt="' . $image['alt'] . '" />';
                $html_out .= '</div>';
    
                $html_out .= '</div>';
            endif;
    
            endwhile;
    
            $html_out .= '</div>';
    
        endif;
    
        return $html_out;
    
    }
    
    add_shortcode('mbgc_gallery', 'mbgc_gallery_shortcode');

    In my field group, the return value is Image URL. Should it be something else?

  • The moment I changed $image['url'] to just $image the url outputted and no more error, but for the alt it was still an issue.

  • Ah, changed the return value to Image Array and that worked. Whoops.

  • I was about to ask what you were returning reading the OP. Glad you got it worked out.

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

The topic ‘Illegal string offset \'url\' issue’ is closed to new replies.