I am new to WordPress and I would appreciate some cool advice here.

I have changed the header.php file in the Editor to include an image. I wonder if it is possible to automatically display one of 9 possible images depending on the date (ie. rotate them)

1 Answer 1


The following code will cycle between the 9 pics. 1st day of the year = pic0, 2nd = pic1...359th = pic9, 360th = pic0, etc.

$pic_array = array(

$d = (int) date('z') % 9;
$todays_pic = $pic_array[$d];
echo $todays_pic;

Hopefully you're not changing a parent theme's header.php!

  • Thanks ! Although it is probably not a perfect rotation, since on 31 of a month it will display image #4 and on the next day it will display image #1, however, it works for me. What do you mean "Hopefully you're not changing a parent theme's header.php!" ?
    – Wartin
    Commented Jan 18, 2013 at 2:25
  • Actually, my code rotation is based on the days of the year. So excess repeats will only occur on pic0-pic6 once per year, e.g, day 365 will be pic6 then day 1 will roll back to pic0 (but you probably won't be using same setup that long!) RE: not changing parent theme's header.php, soon as you update (on purpose, or by mistake) you'll lose any cusomizations. See the WordPress Codex on making child themes, pretty painless. There's even a plugin to automate it for you.
    – akTed
    Commented Jan 18, 2013 at 2:32
  • The reason I made it based on the year instead of the month is because of February. 28th would be pic0 and so would March 1st. If we were in March right now I probably would've used by month instead. :)
    – akTed
    Commented Jan 18, 2013 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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