Balkhis - Vision For Success

Random Header Images for Your Blog

Dear Readers, I would like to thank you for reading this post. I highly value your feedback and would like to know more about my readers. Follow me on Twitter

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

Random Header Images for Your Blog

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.



To stay updated with the blog, please consider subscribing to my full feed RSS. You can also subscribe by Email and have new posts sent directly to your inbox. I hate spam as well, so I promise you that you will not be spammed.
Add to Social Bookmarks:
Add this Article to Digg Add this Article to Stumbleupon Add this Article to Del.icio.us Add this Article to Reddit Add this Article to Newsvine Add this Article to Technorati

RSS feed

12 Comments

Comment by How to Articles
2009-04-17 10:15:00

This is a very cool idea.

Might give it a try.


 
Comment by Blog Expert
2009-04-17 10:42:44

That is a sweet idea but probably not for me. Definitley good for some of my clients.


 
2009-04-17 11:20:04

I might give that a try too. Do you have any other code to spice up a page or two?


Comment by Syed Balkhi
2009-04-17 11:25:20

It depends on what type of codes you are looking for. Ask me a question and I will share it.


 
 
Comment by Used Tires
2009-04-18 01:33:51

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


Comment by Syed Balkhi
2009-04-18 06:27:24

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.


Comment by Used Tires
2009-04-19 17:06:33

Thanks for clearing that up Syed :)

(Comments wont nest below this level)

 
 
 
Comment by marc lohan
2009-04-18 07:51:03

its a nice idea.surely i will try it.thanks


 
Comment by Normal Joe Subscribed to comments via email
2009-04-18 08:52:47

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.


Comment by Syed Balkhi
2009-04-18 18:08:12

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.


 
 
2009-04-21 05:55:23

Hey, thanks, I didn’t think this was even possible, thanks for the info! Will try this on one of my autoblogs.


 
Comment by Web Design Beach
2009-04-21 13:51:42

Hehe nice and very easy tip. I am sure many will find use of it, as it can break standard flow on some sites.


 

Sorry, the comment form is closed at this time.

Subscribe to Balkhis via RSS
Subscribe to Balkhis via Email Pimp My Blog