1

I have a block with an image field type:

array(
    'type' => 'attach_image',
    'heading' => esc_html__("Image"),
    'param_name' => 'bg_image',
    'value' => __(''),
)

To extract the image, I'm doing the following:

$getImage = shortcode_atts(
    array(
        'bg_image'  =>  'bg_image',
    ),
    $atts
);

$image_ids = explode(',',$getImage['bg_image']);
foreach($image_ids as $image_id) {
    $images = wp_get_attachment_image_src($image_id, 'full');
    $image = $images[0];
}

And outputting it like so:

$output .= "<div class='bgImg' style='background-image:url(". $image .")'></div>";

I have set an image to that field type and saved it. However, url is showing up empty and var_dump($image) returns null. Why is this?

Freddy
  • 683
  • 4
  • 35
  • 114

1 Answers1

0

check you $var if is equal put correctlly