If you would like to get a random image for your websites’s background every time you load a page this mini tutorial is for you. I’m assuming you’re using the full screen background image method explained in this post first: Full screen background image in your wordpress website (or any website). If you aren’t you’ll need to implement it first so go ahead an read the post.

Glad you’re back, now lets get to business. We’re going to use a rotator script by Dan Benjamin, it is explained in a great A List Apart article but we only need the code available here: http://d.alistapart.com/randomizer/rotate.txt

1.- Take Dan Benjamin’s code and save it as a PHP file, we’re going to call it “rotate.php”

2.- Via FTP create a directory called “bg” in your root directory and inside place the rotate.php file and any images you want to serve as backgrounds for your site.

3.- Now, if you implemented the  full screen background image method mentioned above right you inserted an inline <img> element somewhere in your code like this one:

<img id="bg_image" src="/bg.jpg" />

We’re going to change that line to call our PHP script instead of an image, so our line of code should end up like this:

<img src="/bg/rotate.php" id="fsb_image"/>

Now thanks to the script every time we load a page the path of the script in that line will be replaced for the path to a randome image inside our bg directory, thus loading a random backgrund every time.