Home Contact Sitemap
Website design, development & Internet marketing in Devon and Cornwall
Four Degrees West Limited
This entry was posted on Tuesday, February 22nd, 2011 at 6:45 pm and is filed under Articles. You can follow any responses to this entry through the RSS 2.0 feed.

Random CSS background for Wordpress theme

Posted on February 2011 in 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.

Bookmark and Share

Leave a Reply

You must be logged in to post a comment.