I want to create a random background image for a div that changes every time the page loads. I am using classic Toolset views and a Genesis child theme.
Solution:
- Create an image custom field and make it a repeating field with the slug set to "slider-images."
- Create a shortcode as described in the documentation link below.
- To use the random image as a background, add custom HTML code inside the content template or wherever you want to use the shortcode, with the following format:
<div class="background-container" style="background-image: URL([types field='slider-images' index="[generate-rand-num field='slider-images' output='raw']"][/types])">
Content of the DIV
</div>