Free Wordpress Blog Setup

How to Add Random Header Images to Your WordPress Blog

By Editorial Staff in Tutorials
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.

What Next?

Digg it
Save This Page
Subscribe to WPBeginner
Stumble it
Free Wordpress Blog Setup

Comments

No Responses to “How to Add Random Header Images to Your WordPress Blog”

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar