10
Apr/05
6

Changed Header Image

I’ve made a simple small change in the top header image. I’ve created 7 images and every time you reload the page a php script loads one of the 7 images randomly.

How I did it?

I’ve created 7 images and uploaded them in my theme images folder. I then removed my CSS header code and pasted it into the header template editing it to look like this.

#header {
   background: url("< ?php bloginfo('stylesheet_directory'); ?>/images/head0< ?php echo rand(1, 7); ?>.jpg" ) no-repeat bottom center;
 }

And that’s it. The php rand(1, 7); function creates a random number from 1 to 7 inclusive and that loads the appropriate picture. Simple yet effective.

Tagged as:
Comments (6) Trackbacks (1)
  1. Well, it’s not exactly as you say it is ;) It loads one of the seven images randomly.

  2. Edited. Thanks for the correction. :D

  3. Ok i tried the code you show (thanks by the way!!) but images won’t show up and when I view source this is what i get:

    #header { background: url("http://www.jeremiahandsarahowen.com/wp-content/themes/mx4_theme/images/head01.jpg�) no-repeat bottom center;
    }

    any ideas why I am getting that goofy acsii question mark there?? Thanks!

  4. I would imagine that you get that ascii because your quotes ( ” ) are being translated into ascii try checking your source to see if you get something like &(number);.
    Other than that I don’t realy know. Maybe it would help if you typed the code other than copy paste.

  5. Yup that was it… I typed it and it was fine… :)

  6. Glad I could help :D

Leave a comment

Note: This post is over 5 years old. You may want to check later in this blog to see if there is new information relevant to your comment.

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.