Many blog have different header image which keep on changing from page to page, which give the site a rich look. Here’s a simple random function which displays different header images on your WordPress site. To achieve this php rand () function is used, which allows us to get a random number between 1 and 99.
If the random number is less than or equal to 33, the first header image will be displayed. Less the 66, the second header image will be displayed, and then the 3 will be showed if it is less than or equal to 99.
Paste this code in your header.php file:
<?php $result_random=rand(1, 99); if($result_random<=33){ ?> <a href="http://www.livetut.com/" title="LiveTUT" rel="home"> <img src="http://www.livetut.com/wp-content/uploads/2012/06/Logo2.png" alt="LIVETUT" /> <span>LiveTUT</span></a> <?php } elseif($result_random<=66){ ?> <a href="http://www.livetut.com/" title="LiveTUT" rel="home"> <img src="http://www.livetut.com/wp-content/uploads/2012/06/Logo1.png" alt=LIVETUT"/> <span>LiveTUT</span></a> <?php } elseif($result_random<=99){ ?> <a href="http://www.livetut.com/" title="LiveTUT" rel="home"> <img src="http://www.livetut.com/wp-content/uploads/2012/06/Logo1.png" alt="LIVETUT"/> <span>LiveTUT</span></a> <?php } ?>
Method two:
In this your header image can be placed in a folder with different extension numbers. Such as
headerimage_1.gif
headerimage_2.gif
headerimage_3.gif
Now add this code to your header.php file where your image likes to be displayed.
Paste this code:
<img src="http://path_to_images/headerimage_<?php echo(rand(1,3)); ?>.jpg" width="image_width" height="image_height" alt="image_alt_text" />
Make sure you change the image as 1,2,3 with proper extension.