Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ACF: Random image from Gallery
@jared-rice

This comment has been minimized.

Copy link

commented Jul 5, 2019

This worked great for me, thanks!

Heres a background image conversion if anyone is interested:

<?php
     $gallery = get_field('images');
     $rand = array_rand($gallery, 1);

     if( $gallery ):
           $background_image_full = wp_get_attachment_image_src( $gallery[$rand]['ID'], 'full'); ?>
	   <div style="background-image: url('<?php echo esc_url($background_image_full[0]); ?>')">
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.