Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ACF: Random image from Gallery

This comment has been minimized.

Copy link

jared-rice commented Jul 5, 2019

This worked great for me, thanks!

Heres a background image conversion if anyone is interested:

     $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.