Support

Account

Home Forums Add-ons Gallery Field Random Gallery Image with wp_get_attachment_image() Reply To: Random Gallery Image with wp_get_attachment_image()

  • Yes, sorry, perhaps I should have been more clear. I’m not sure how to make the $rand variable apply. I tried things like this, to no avail:

    
    <?php 
    	$images = get_field('gallery', 'option');
    	$size = 'full'; // (thumbnail, medium, large, full or custom size)
    	$rand = array_rand($images, 1);
    
    	if( $images ): ?>
    	       	<?php echo wp_get_attachment_image( $images[$rand], $size ); ?>
    <?php endif; ?>