Ketan
Ketan

Reputation: 619

How to display wordpress ACF plugin custom image field image

I have used ACF plugin to add custom post meta box image field. My custom image field name is homepage_full_width.

How can i display post thumbnail image using this custom field image.

thanks.

Upvotes: 3

Views: 4718

Answers (2)

Vince
Vince

Reputation: 41

You can use image ID as the return type of the ACF custom image field then you can use the wp_get_attachment_image() function to generate the image HTML.

$image = get_field('homepage_full_width');
$size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)

if( $image ) {

    echo wp_get_attachment_image( $image, $size );

}

UPDATE

Use image Object as the return type then try

<?php 
$imageBg = get_field('homepage_full_width'); 
$bg = $imageBg ? $imageBg['url'] : ''; 
?>
<div class="zl-homefullwidth-img parallax_bg skrollable skrollable-between" style="transform: translate3d(0px, 0.382158%, 0px);background-image: url(<?php echo $bg; ?>)"></div>

Upvotes: 4

zarex360
zarex360

Reputation: 410

You can do it two ways:

  1. you can use the get_field('homepage_full_width') in your themes php files where you want it, you can see the documention for it here

  2. You can use and shortcode to display it: [acf field="homepage_full_width"]

You can read the documention for the shortcode here

Upvotes: 0

Related Questions