The problem. This is not really a problem, but many WordPress users would love to be able to display a random header image to their readers.
The solution.
- Once you have selected some images to be your header images, name them 1.jpg, 2.jpg, 3.jpg and so on. You can use as many images as you want.
- Upload the images to your wp-content/themes/yourtheme/images directory.
- Open header.php and paste the following code in it:
1$num= rand(1,10);//Get a random number between 1 and 10, assuming 10 is the total number of header images you have2<div id="header"style="background:transparent url(images/.jpg) no-repeat top left;"> - You’re done! Each page or post of your blog will now display a random header image.
Code explanation. Nothing hard here. We simply initialized a $num variable using the PHP rand() function to get a random number between 1 and 10. Then, we concatenate the result of the $num variable to the path of the theme we are using.
