≡ Menu

Display Random or Rotating Images in WordPress Header

Just a while ago, iI wrote about How to highlight admin comments in wordpress. In today’s post, I want to show you the coding for rotating a number of images in your blog header.
Rotating images can grab the attention of your visitors in a few seconds. So if you want to grab their attention, then try the following coding work for this purpose.

How to Display Rotating OR Random Images in header?

Step 1:- Collect the images you want to add in your blog header.

rotating images in wordpress header


Step 2:- Make sure that all the images have the same size. Now name the images in the following sequence


The sequence for the ‘name of images’ must remain the same as mentioned above.

Step 3:- Upload all the images to your image directory and paste the below code in your header.php file.

<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 to replace the http://path_to_images/headimage_ with the correct one. Also replace the image_width and image_height with the actual values of the image sizes.

Step 4:- Once done, save the file and visit your blog to see the image rotation in action.

Do check our other articles about adding Favicon to your blog and Retweet button.

{ 0 comments… add one }

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.