How to Display WordPress Random Header Images

Make your header images dynamic. After applying this technique header image will be change on each visit. You can select as many images as you want to rotate randomly. It brings life to a blog.

First you need to name your images in this format:

  • header_1.gif
  • header_2.gif
  • header_3.gif

You must separate the name with an underscore. You can change the headerimage text to himage or anything you like.

Once you have done that paste the following code in your header.php where you would like the images to be displayed or in any other file.

<img src=”http://path_to_images/headerimage_<?php echo(rand(1,3)); ?>.gif”
width=”image_width” height=”image_height” alt=”image_alt_text” />

Make sure that you change the number 3 if you decide to do more than 3 images. This code is not exclusive for WordPress, it will work with any php based platform.

Twitter Digg Delicious Stumbleupon Technorati Facebook

No comments yet... Be the first to leave a reply!