WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question
up vote 2 down vote accepted

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!

share|improve this answer
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 Jan 18 '13 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 Jan 18 '13 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 Jan 18 '13 at 2:40

Your Answer


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.