Support

Account

Home Forums General Issues How to use the image field for backgrounds? Reply To: How to use the image field for backgrounds?

  • Image field should return image url, not id or array.
    If you want more control you can set to return id and from that

    <?php
    	$imgID = get_sub_field('background_image');
    	$imgSize = "full"; // (thumbnail, medium, large, full or custom size)
    	$imgArr = wp_get_attachment_image_src( $attachid, $size );
    	// url = $image[0];
    	// width = $image[1];
    	// height = $image[2];
    ?>
    <?php 
    if( !empty($image) ): ?>
    	<div id="mainPhoto" style="background-image: url(<?php echo $imgArr[0]; ?> );">
    		<div id="pageTitle">
    			<?php the_field('page_title'); ?>
    		</div>
    	</div>
    <?php endif; ?>