(+84) 463.28.7979

How to Add Random Header Images to Your WordPress Blog

Often times bloggers want to have a header image in their design. Usually these images are static, and it gets boring after a while. You will probably see that there are numerous WordPress blogs that has dynamic header images which rotates randomly. In this tutorial, we will show you how you can add random header images to your blog.

If you are a new user, you would probably think that something of this sort is extremely hard and requires a special plugin. We actually rate this plugin at a beginner level.

First thing you need to do is get the images. Make sure you stay consistent with the sizes of these images as well as the extension. So if you have one image that is a .jpg then all others must also be .jpg. There is no limit to how many images you can have rotating, but for the sake of this tutorial, we will use 3 images to rotate.

Random Header Images

Once you have found the images, you may name them in a sequence like:

  • headerimage_1.gif
  • headerimage_2.gif
  • headerimage_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.

<img src=”http://path_to_images/headerimage_<?php echo(rand(1,3)); ?>.jpg”
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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>