Last active
November 22, 2021 21:22
-
-
Save addisonhall/45c1fb2ad160f29234e404791a5b93f5 to your computer and use it in GitHub Desktop.
ACF random image for GeneratePress background image URL
This file contains 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 | |
add_filter( 'generate_page_hero_background_image_url', function( $url ) { | |
$headers = array( | |
esc_url(get_field('radnomizer_image_one')), | |
esc_url(get_field('radnomizer_image_two')), | |
esc_url(get_field('radnomizer_image_three')), | |
esc_url(get_field('radnomizer_image_four')), | |
esc_url(get_field('radnomizer_image_five')) | |
); | |
// remove empty values from array | |
$headers = array_values( array_filter( $headers ) ); | |
$url = $headers[ rand( 0, count( $headers ) -1 ) ]; | |
return $url; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in reference to this: https://generatepress.com/forums/topic/random-background-images-on-pages/?fbclid=IwAR0dm41yQHwxkAHkM6KpXj8lcLP1MUaJtIOg5cOWG2i-jB17dAmWZ1l346M#post-1093883