admin管理员组

文章数量:1134587

I have a problem with an acf function for displaying an image by array.

I can get my image to work well when I upload it to the field associated with it. On the other hand, when I don't put an image, because the field is not mandatory, I get this error warning: trying to access array offset on value of type bool

My image field is in a field group, in a page option and I'm in php 8.0

My code looks like this

<?php
$image = get_field('my_group','option');
$image_name = $image ['my_img'];
if ($image):?>
    <img src="<?php echo esc_url ($image_name['url']); ?>" alt="<?php echo esc_attr($image_name['alt']); ?>" />
<?php endif;?>

本文标签: functionswarning trying to access array offset on value of type bool ACF field image group