Home Forums ACF PRO Replace image with random image


Replace image with random image

  • Our website was designed by third party, and there is an ACF image on the front page that I would like to change to a random image that would be different each time a user reloads the page. I have found this code that seems like it would work, but I’m not sure where I need to place this code:


    $images = get_field(‘header_image’, ‘option’);
    $rand = array_rand($images, 1);

    if( $images ): ?>
    ” alt=”<?php echo $images[$rand][‘alt’]; ?>” />
    <?php endif; ?>

    I am not a coder by any stretch of the imagination, but I’m comfortable changing files over FTP. I always just create a backup of the file first just in case I FUBAR something. Can anyone help me out?


Viewing 1 post (of 1 total)

The topic ‘Replace image with random image’ is closed to new replies.