Random CSS background for WordPress theme

Feb 22, 2011 by     No Comments    Posted under: Articles

I’ve just been searching to find the best way to randomly change the header background image for my WordPress theme and couldn’t believe some of the complex solutions I found, whilst browsing some mind blowing over engineered ideas I realised you just need to do this…

 <div id=”header” style=”background-image: url(<?php bloginfo(‘stylesheet_directory’); ?>/images/<?php echo (“headerimg”.rand(0,4).”.jpg”)?>)” ;>

The above solutions just checks the images/ folder of your theme for 5 images headerimg1.jpg, headerimg2.jpg, headerimg3.jpg, etc etc.

Got anything to say? Go ahead and leave a comment!

You must be logged in to post a comment.

Relevant Links:

Bed & Breakfast Scarborough

Beautiful bed and breakfast accommodation in the village of Wykeham just 6 miles from Scarborough. Large double rooms and private bathrooms available. Bed and Breakfast Scarborough