Random Header Images for Your Blog
I was asked a question via email if there are advantages of having random header images. I say why not. If you have a website that contains a header image, it is much better for you to change things up, spice it up a little. I would take the dynamic header image any day.
Most people think this would be a pain in the ass and it requires some plugin. And if you are like me, you don’t want to go through the hassle of searching the plugin. Well how about I tell you that there is no need for a plugin to do this. I say this tutorial is on Beginner Level.
All you really need is a simple php code that I am about to give you in this post.
Get the Header Images

For demonstration’s sake I will be only using three images, but you can use as many images you want. Few things to keep in mind that you must have all of these images in the same extension. Meaning if you have one image as a .gif then the other two must also be .gif. If you have one as .jpg then the other two must also be .jpg. I hope you guys get the concept.
So the three files we would use are:
- himage_1.jpg
- himage_2.jpg
- himage_3.jpg
You do not have to use the same names as I do. It can be header_1 or head_1… anything you really like. Just make sure there is an _ separating the number. Also make sure that these images are the same size, so it fits your design’s dimension and doesn’t make your site W3 Invalid.
If you need help finding stock photos then I have compiled a list of 11 free stock photo sites.
Implementation
This code would work just about work on any platform that is based on php. So if you are using wordpress then you are ok. Anyone else who wants to use it on their php websites, this would work as well.
<img src="http://path_to_images/himage_<?php echo(rand(1,3)); ?>.jpg"
width="image_width" height="image_height" alt="image_alt_text" />
If you are using more images, make sure that you change the number from 3 to however many images you have. All what this code does is it takes your image and choose one randomly. It is that simple.
I hope you guys like it.





















Hey, I am Syed Balkhi, The guy who is behind Balkhis Inc. I entered the industry back in 2002 not knowing a single thing. I barely spoke English at that time. In the past six years, my language barrier has been eliminated. Aside from English, now I also speak html, and php. Along with the languages I have also managed to master a few arts. Art of web-designing started when I first entered. Messing around with photoshop, I learned how to create my first web design. Now I founded a web designing firm Uzzz Productions. After running numerous amount of websites in various niche, I have mastered the art of web-development. Now I am compiling a resource of what I already know, and what I am learning on this blog. This resource is to help me if I ever need a guide to look back to, and it is help my fellow webmasters.




This is a very cool idea.
Might give it a try.
That is a sweet idea but probably not for me. Definitley good for some of my clients.
I might give that a try too. Do you have any other code to spice up a page or two?
It depends on what type of codes you are looking for. Ask me a question and I will share it.
I like the changing of the header, it can add a freshness look to the blog. Although I have heard…. and maybe someone can de-mythfy this, that if Google crawls your website at the wrong time, it can goof up the spiders because of the “random” effect.
Till then,
Jean
Absolutely not right about the google bot. Google bot does not see the dynamic image. They see a static image. It cannot screw you over. These images are solely for decoration purposes. You are not suppose to use good anchor tags or text on top of it.
Thanks for clearing that up Syed
its a nice idea.surely i will try it.thanks
Awesome man! This is a sweet little code, not sure where I’d use it, but I’m sure I could find a place!
thanks.
Well you can really use it just about anywhere on your site like headeer images maybe sidebar images that you want to change. It really works well in simple designs.
Hey, thanks, I didn’t think this was even possible, thanks for the info! Will try this on one of my autoblogs.
Hehe nice and very easy tip. I am sure many will find use of it, as it can break standard flow on some sites.