Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
Excellent, thanks. These lines should replace the existing one in header.php, right? –  Adam Matan Jun 11 '11 at 17:03
    
@Adam Matan, If there is already a <img /> in your header.php then yes that's the one you would replace. –  mike23 Jun 11 '11 at 17:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.