Last active
July 24, 2024 18:11
-
-
Save tjhole/8054985 to your computer and use it in GitHub Desktop.
ACF: Random image from Gallery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $gallery = get_field('images'); | |
| $rand = array_rand($gallery, 1); | |
| if( $gallery ): ?> | |
| <img src="<?php echo $gallery[$rand]['sizes']['large']; ?>" alt="<?php echo $gallery[$rand]['alt']; ?>" /> | |
| <?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This worked great for me, thanks!
Heres a background image conversion if anyone is interested: