Bloggers often like to have a header image on their WordPress website. These images are usually static, and after a while, it’s boring for the visitors. You will probably see that there are numerous WordPress blogs that have dynamic header images which rotate randomly. Let’s discuss on how you can add random header images to your WordPress blog.
If you are just starting out, you would probably think that this os relatively complex and requires a plugin.
The 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. If you have an image in a .jpeg format then all others must also be in the same format. There is no upper limit on how many images you can use, in this example, let’s do a 3-image carousel!
Once you have found the images, you might want to name them in a sequence like:
You must separate the name with an underscore. You can change ‘img’ to anything you like.
After that, write the following code in your theme’s header.php where you would like the images to be displayed.
<img src="http://path_to_images/img_<?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 will work on any platform, which is based in PHP, not just limited to WordPress.