Title: Random background image
Last modified: August 18, 2016

---

# Random background image

 *  Resolved [oval](https://wordpress.org/support/users/oval/)
 * (@oval)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/random-background-image-1/)
 * Hi guys, I would like to place a random background image function on my main 
   wordpress page so that each time the user visits the blog or refreshes the page,
   a random background image appears on the entire page.
 * I had acquired a javascript for the random bg image and tried to implement it
   in the header.php but I had no luck. Is there any other way I can do this? Any
   advice or info is appreciated.
 * Best,
    Oval

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [iscifi](https://wordpress.org/support/users/iscifi/)
 * (@iscifi)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/random-background-image-1/#post-589574)
 * Ya I use one on my blog, not using javascript but a php script called rotate.
   php
 * simple HTML, but adjust to what you need inside your header.php file
 * <background=”rotate.php”>
 * Matt of wordpress fame! has an example here:
    [http://photomatt.net/scripts/randomimage/](http://photomatt.net/scripts/randomimage/)
 * peace
 *  Thread Starter [oval](https://wordpress.org/support/users/oval/)
 * (@oval)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/random-background-image-1/#post-589632)
 * Dear Iscifi,
 * Thank you so much for the tip! Works like a charm.
 * Oval
 *  [Jauhari](https://wordpress.org/support/users/jauhari/)
 * (@jauhari)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/random-background-image-1/#post-589913)
 * I will use it too 😉
 *  [Redsword](https://wordpress.org/support/users/redsword/)
 * (@redsword)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/random-background-image-1/#post-589965)
 * This is great code. Simple & elegant.
 * I do have one question on implementation.
 * I am rotating the background image for the pages.
 * However, I want to use a different random background image on the index.php and
   single.php templates. I am using the same code to get the image in each file
 *     ```
       <style type="text/css">body {
       	background-image: url(../../../images/backgrounds/rotate.php);
       }
       ```
   
 * However, when I go from page to page my FireFox cache is loading the same background
   image instead of getting a new one (Internet Explorer 7 seems to load it new 
   each time). If I <shift>+”Refresh” I get a different background each time but
   unless I do the force refresh each page loads with the cached background.
 * Is there a good way to work around this?
 * I assume I can use a different “random image” directory for each template and
   since I would call the random image from a different place there would not be
   the same one in the cache, but that seems very clunky.
 * Any ideas?
 *  [CowboyFrank](https://wordpress.org/support/users/cowboyfrank/)
 * (@cowboyfrank)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/random-background-image-1/#post-589971)
 * I have noticed this too. Solution?
 *  [mrmonte12345](https://wordpress.org/support/users/mrmonte12345/)
 * (@mrmonte12345)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/random-background-image-1/#post-589972)
 * how could i do a rotating image in the header? same code?
 *  [CowboyFrank](https://wordpress.org/support/users/cowboyfrank/)
 * (@cowboyfrank)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/random-background-image-1/#post-589973)
 * That’s what I’m using it for…
 *  [Redsword](https://wordpress.org/support/users/redsword/)
 * (@redsword)
 * [18 years ago](https://wordpress.org/support/topic/random-background-image-1/#post-589975)
 * Hi guys,
 * It has been a few weeks. Does anyone have a clue on the different background 
   on each page?
 *  [gorb-loonder](https://wordpress.org/support/users/gorb-loonder/)
 * (@gorb-loonder)
 * [18 years ago](https://wordpress.org/support/topic/random-background-image-1/#post-589976)
 * If you insert the style tag `<style type=”text/css”>body {
    background-image:
   url(../../../images/backgrounds/rotate.php); }` into a text widget at the bottom
   of your sidebar it should reload with every page load.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Random background image’ is closed to new replies.

## Tags

 * [background](https://wordpress.org/support/topic-tag/background/)
 * [image](https://wordpress.org/support/topic-tag/image/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 7 participants
 * Last reply from: [gorb-loonder](https://wordpress.org/support/users/gorb-loonder/)
 * Last activity: [18 years ago](https://wordpress.org/support/topic/random-background-image-1/#post-589976)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
