This PHP code enables you to display a random image which changes on every page load.
The solution only uses 3 lines of code in a custom function with WordPress or theme specific hooks like
Note: If you’re wanting to rotate images in your themes header image, that functionality is already built into the WordPress customizer so you won’t need this solution which works anywhere you place the code in a template file or in any hook location.
In this example, the code uses 3 images from your child themes images folder and displays a different image every time the page loads.
The images should use the file names:
You can change the filename and extension in the PHP code to match your images.
Here’s the code for registered members:
You need to pay to fully access this tutorial.
Enjoy unlimited access & coding support by registering.