Alternate header image

Is there a convenient and configurable way to alternate between different header images?

The main features I’m looking for are:

  • Random select from a set of images
  • Specific header image in given date range (a la Google Doodle)
  • Specific header image for specific posts or pages

1 Answer
1

You can try this

Random from a set of images :

<img src="http://www.mywebsite.com/images/image_<?php echo rand(1,10); ?>.jpg" alt="" />

This would load a random image from image_1.jpg, image_2.jpg … to image_10.jpg

or

$images = array("cool_image.jpg", "nice_pic.jpg", "sunset.jpg");
$rand = array_rand($images);

<img src="http://www.mywebsite.com/images/<?php echo $images[$rand]; ?>" alt="" />

This would select a randow image from thoses specified in the $images array.

Date range :

<?php
if ((date('m') == 3) && (date('d') == 17)) { ?>
    <img src="http://www.mywebsite.com/images/stpatrick.jpg" alt="" />
<?php } ?>

This would show an image for St Patricks

Specific posts or pages :

See : Change image based on menu item id

Leave a Comment