Main objective of this blog post is to give you an idea about how to add random header images to wordpress blog



Step 1 Introduction

Ever imagined how one can tweak WordPress codes and get awesome results? Today I will teach you one such tweak on how to add random images to header in WordPress without any plugin. But before that, let us know something about header images. Usually those images are static. You will probably see numerous WordPress blogs that has dynamic header images which rotate randomly.


Step 2 Now let us start the tweak.

First select the images which you want to put in header section. Make sure all your images have same extension. If you have one image in .jpg format then all other images should be in .jpg format. Here we will be taking only 3 random images (as shown below). You can rotate any number of images. 



Step 3 Selecting Images

Here, when you select your images to put in header then you should name them in a sequence like:

  • Image-header_1.jpg
  • Image-header_2.jpg
  • Image-header_3.jpg

Following above naming structure will be beneficial while traversing images. You should separate the names with an underscore. You can change the header image text to himage or anything you like.

After that you need to paste following code into header.php where you would like the header image to be displayed.

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

Step 4 Header.php

Here in above code rand(1,3) will generate any random number between 1 and 3(including both 1 and 3). You can now see why naming structure had been important. You just need to change the sequence number of images which will be the filename of images. That becomes a lot easier, isn’t it?

Now if you change the number of images in header, make sure you change numbers inside random function. It works on php based platform.

I hope you find this blog is very helpful while working with wordpress customization. Let me know in comment if you have any question regarding wordpress. I will reply you ASAP.

Got an Idea of WordPress Web Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best WordPress Web Development Company in India.

I am passionate Web Designer. Love to develop website with HTML 5 and CSS 3. And also like to share tips & tricks about latest web trends

face mask Belial The Demon Headgear Pocket Staff Magic